Challenge - 5 Problems
Brace Expansion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Output of a simple for loop with brace expansion
What is the output of this Bash script?
for i in {1..5}; do echo $i; doneBash Scripting
for i in {1..5}; do echo $i; done
Attempts:
2 left
💡 Hint
Brace expansion generates a sequence of numbers separated by spaces.
✗ Incorrect
The brace expansion {1..5} generates numbers 1 to 5. The loop echoes each number on its own line.
💻 Command Output
intermediate1:30remaining
Behavior of for loop with variable expansion inside range
What will this script output?
start=3
end=7
for i in {$start..$end}; do echo $i; doneBash Scripting
start=3 end=7 for i in {$start..$end}; do echo $i; done
Attempts:
2 left
💡 Hint
Brace expansion happens before variable expansion in Bash.
✗ Incorrect
Brace expansion occurs before variable expansion, so {$start..$end} is not expanded as a numeric range; it becomes the literal string '{3..7}' after variable expansion.
📝 Syntax
advanced2:00remaining
Correct syntax for a for loop counting down with brace expansion
Which option correctly counts down from 10 to 1 using brace expansion in Bash?
Attempts:
2 left
💡 Hint
Brace expansion supports a step value for counting down.
✗ Incorrect
The syntax {start..end..step} allows counting down with a negative step. {10..1..-1} counts from 10 down to 1.
🚀 Application
advanced2:00remaining
Using a for loop with brace expansion to create files
You want to create 5 empty files named file1.txt to file5.txt using a Bash for loop with brace expansion. Which command will do this?
Attempts:
2 left
💡 Hint
Use a loop to run the touch command multiple times with different file names.
✗ Incorrect
Option C loops from 1 to 5 and creates each file with touch. Option C expands to 'touch file1.txt file2.txt file3.txt file4.txt file5.txt' creating all files without a loop; the task requires a for loop.
🔧 Debug
expert2:30remaining
Why does this for loop not print numbers 1 to 10?
Consider this script:
Why does it fail to print numbers 1 to 10?
for i in {1..10} do
echo $i
doneWhy does it fail to print numbers 1 to 10?
Bash Scripting
for i in {1..10} do echo $i done
Attempts:
2 left
💡 Hint
Check the syntax of the for loop header carefully.
✗ Incorrect
In Bash, the for loop header must end with a semicolon or newline before 'do'. Missing this causes a syntax error.