Recall & Review
beginner
What does the brace expansion
{1..10} do in bash?It generates a sequence of numbers from 1 to 10, expanding to 1 2 3 4 5 6 7 8 9 10.
Click to reveal answer
beginner
How can you use brace expansion to create files named file1.txt to file10.txt?
Use the command
touch file{1..10}.txt. This creates 10 files named file1.txt, file2.txt, ..., file10.txt.Click to reveal answer
intermediate
Can brace expansion generate sequences with steps, like every 2 numbers from 1 to 10?
Yes, by using
{start..end..step}. For example, {1..10..2} expands to 1 3 5 7 9.Click to reveal answer
beginner
What happens if you use brace expansion with letters, like
{a..e}?It generates a sequence of letters from a to e: a b c d e.
Click to reveal answer
intermediate
Is brace expansion performed before or after variable expansion in bash?
Brace expansion happens before variable expansion. So variables inside braces won't expand as part of the brace expansion.
Click to reveal answer
What is the output of
echo {3..7} in bash?✗ Incorrect
Brace expansion generates the sequence 3 4 5 6 7.
Which command creates files named test1.txt to test5.txt using brace expansion?
✗ Incorrect
The brace expansion {1..5} generates numbers 1 to 5 for file names.
How do you generate odd numbers from 1 to 9 using brace expansion?
✗ Incorrect
Using a step of 2 with {1..9..2} generates 1 3 5 7 9.
What does
echo {z..v} output?✗ Incorrect
Brace expansion supports reverse sequences, so it outputs z y x w v.
If you run
echo file{$i..10}.txt with i=3, what happens?✗ Incorrect
Brace expansion happens before variable expansion, so $i is not expanded inside braces.
Explain how brace expansion works in bash using the example {1..10}.
Think about how you can quickly list numbers without typing each one.
You got /3 concepts.
Describe how to create multiple files named file1.txt to file10.txt using a single bash command.
Use brace expansion inside the file name.
You got /3 concepts.