Bash Scripting - LoopsWhich of the following is the correct syntax to print numbers 1 to 10 in Bash using a for loop with brace expansion?Afor i in {1..10} echo $i doneBfor i in {1..10}; do echo $i; doneCfor i {1..10}; do echo $i; doneDfor i in {1..10}; do echo i; doneCheck Answer
Step-by-Step SolutionSolution:Step 1: Check for correct loop syntaxThe for loop requires 'in' keyword, the range in braces, and 'do' and 'done' keywords.Step 2: Verify echo command usageVariable $i must be referenced with a dollar sign to print its value.Final Answer:for i in {1..10}; do echo $i; done -> Option BQuick Check:Correct for loop syntax with echo $i = for i in {1..10}; do echo $i; done [OK]Quick Trick: Use 'do' and 'done' with for loops; echo variables with $ [OK]Common Mistakes:MISTAKESOmitting 'do' and 'done'Not using $ before variable in echoMissing 'in' keyword
Master "Loops" in Bash Scripting9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Bash Scripting Quizzes Conditionals - Why conditionals branch script logic - Quiz 2easy Loops - for loop (list-based) - Quiz 5medium Loops - Infinite loops - Quiz 4medium Loops - while loop - Quiz 14medium Quoting and Expansion - Single quotes (literal strings) - Quiz 9hard Quoting and Expansion - Escape characters (\) - Quiz 4medium Quoting and Expansion - Why quoting rules prevent errors - Quiz 14medium User Input - Default values for input - Quiz 11easy User Input - Prompting with read -p - Quiz 8hard User Input - Command-line arguments ($1, $2, ...) - Quiz 8hard