Bash Scripting - LoopsWhy does this script fail?for i in {1..5}; do echo i; doneAVariable i is not expanded with $BBrace expansion is incorrectCMissing 'done' keywordDSyntax error in for loopCheck Answer
Step-by-Step SolutionSolution:Step 1: Check variable usage in echoEcho prints the literal string 'i' because $ is missing before i.Step 2: Confirm brace expansion and loop syntaxBrace expansion and loop syntax are correct, so error is variable expansion.Final Answer:Variable i is not expanded with $ -> Option AQuick Check:Use $ to expand variables in echo = Variable i is not expanded with $ [OK]Quick Trick: Always use $ before variable names to print their values [OK]Common Mistakes:MISTAKESForgetting $ before variable in echoAssuming brace expansion is wrongMissing loop keywords
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