0
0
Bash Scriptingscripting~5 mins

Brace expansion ({1..10}) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A3..7
B{3..7}
C3 4 5 6 7
D7 6 5 4 3
Which command creates files named test1.txt to test5.txt using brace expansion?
Atouch test[1-5].txt
Btouch test{1..5}.txt
Ctouch test{1,5}.txt
Dtouch test1.txt test5.txt
How do you generate odd numbers from 1 to 9 using brace expansion?
A{1..9..2}
B{1..9..3}
C{1..9}
D{2..10..2}
What does echo {z..v} output?
Az y x w v
Bv w x y z
C{z..v}
DError
If you run echo file{$i..10}.txt with i=3, what happens?
AExpands to file3.txt file4.txt ... file10.txt
BOutputs file3..10.txt
CError because variable inside braces
DOutputs file{$i..10}.txt literally
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.