0
0
Bash Scriptingscripting~15 mins

Brace expansion ({1..10}) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Brace Expansion to Generate Number Sequences in Bash
📖 Scenario: Imagine you are organizing a small event and need to create folders numbered from 1 to 10 to store participant files. Doing this manually would take time, so you want to automate it using a simple Bash script.
🎯 Goal: Build a Bash script that uses brace expansion {1..10} to generate a sequence of numbers and create folders named folder1 to folder10.
📋 What You'll Learn
Create a variable with the sequence of numbers from 1 to 10 using brace expansion.
Create a prefix variable for folder names.
Use a loop to combine the prefix and numbers to create folder names.
Print the folder names to verify the output.
💡 Why This Matters
🌍 Real World
Automating repetitive tasks like creating multiple folders or files saves time and reduces errors.
💼 Career
Knowing how to use brace expansion and loops in Bash is useful for system administrators, DevOps engineers, and anyone working with Linux shell scripting.
Progress0 / 4 steps
1
Create a variable with numbers 1 to 10 using brace expansion
Create a variable called numbers and assign it the sequence generated by brace expansion {1..10}.
Bash Scripting
Need a hint?

Use numbers=({1..10}) to create a sequence from 1 to 10.

2
Create a prefix variable for folder names
Add a variable called prefix and set it to the string folder.
Bash Scripting
Need a hint?

Set prefix=folder to use as the folder name start.

3
Use a loop to combine prefix and numbers to create folder names
Write a for loop using num as the iterator to go through ${numbers[@]}. Inside the loop, create a variable folder_name by combining $prefix and $num.
Bash Scripting
Need a hint?

Use for num in ${numbers[@]} and combine with prefix inside the loop.

4
Print the folder names to verify the output
Inside the loop, add a echo statement to print the folder_name variable.
Bash Scripting
Need a hint?

Use echo "$folder_name" inside the loop to print each folder name.