Chapter 63: Bash Quiz
Bash Quiz
This is not just another lecture. This is the moment where we stop reading about Bash and start proving to ourselves that we actually understood something.
A Bash quiz is a short set of questions + small coding challenges that test:
- Do you remember the syntax rules?
- Can you spot mistakes quickly?
- Can you write correct code under pressure (even if small)?
- Do you understand how commands, variables, conditions, loops, etc. actually behave?
Why quizzes matter (teacher speaking from heart):
- Reading feels easy → but 70–80% is forgotten in 24 hours
- Doing a quiz forces your brain to retrieve information → memory becomes 5–10× stronger
- Real interviews / freelance tasks / server emergencies are basically live quizzes
- When you get a question right → dopamine hit → you feel “yes, I know this!”
- When you get it wrong → you learn 10× more than when you just read the correct answer
So today I’m giving you a proper Bash Quiz — beginner to intermediate level — exactly covering everything we’ve studied so far.
Rules for Doing the Quiz the Right Way
- No peeking at previous messages or Google for the first attempt
- Time yourself — try to finish in 20–30 minutes
- Write answers in a text file or on paper — don’t just think
- For coding questions — actually type & run the code in terminal
- After finishing → check my answers & explanations below
- For every wrong answer → rewrite the correct version 3 times by hand
Ready? Let’s go!
Bash Quiz – Level 1 to 2 (30 Questions + 5 Mini-Scripts)
Part A – Theory / Syntax Questions (Choose or Fill)
- What is the correct way to assign a variable? a) name = “Rahul” b) name=”Rahul” c) $name = “Rahul” d) name =Rahul
- Which of these will correctly print the value of variable $city? a) echo $city b) echo ‘$city’ c) echo “$city” d) echo {city}
- What does this line do? today=$(date +%Y-%m-%d)
- How do you safely loop over all elements of an array that may contain spaces? a) for i in $array b) for i in ${array[@]} c) for i in “${array[@]}” d) for i in $array[*]
- Which test syntax is modern & recommended? a) [ “$a” == “yes” ] b) [[ “$a” == “yes” ]] c) (( “$a” == “yes” )) d) test “$a” = “yes”
- What is the correct numeric “greater than” operator inside [[ ]]? a) > b) -gt c) gt d) >=
- How do you make a variable local inside a function? a) var=”value” b) local var=”value” c) VAR=”value” d) export var=”value”
- What does */10 * * * * mean in crontab? a) Every 10 seconds b) Every 10 minutes c) Every 10 hours d) Every 10th day
- What command makes a script executable? a) chmod +x script.sh b) chmod 777 script.sh c) sudo bash script.sh d) source script.sh
- What is the shebang line? Write it correctly.
Part B – Spot the Mistake (Find & Fix)
|
0 1 2 3 4 5 6 7 |
name = "Priya" echo Hello $name! |
|
0 1 2 3 4 5 6 7 8 |
if [ $age > 18 ]; then echo Adult fi |
|
0 1 2 3 4 5 6 7 8 9 |
for file in *.txt do echo $file done |
|
0 1 2 3 4 5 6 7 8 9 10 11 |
count=5 while count > 0 do echo $count count-- done |
|
0 1 2 3 4 5 6 7 8 9 |
greet() { echo "Hello $1" } greet Rahul Mumbai |
Part C – Write Mini-Scripts (Type & Run These)
- Easy Write mood.sh that asks “How are you feeling? (good/ok/bad)” and prints:
- good → “Super! Keep shining ✨”
- ok → “Nice — one step at a time 😊”
- bad → “It’s okay — tomorrow will be better 💪”
- anything else → “Tell me properly next time!”
- Medium Write backup_today.sh that:
- Creates backup name Documents_YYYY-MM-DD.tar.gz
- Backs up only ~/Documents
- Prints success or error message
- Medium-Hard Write count_by_ext.sh that counts how many .txt, .jpg/.png, .pdf files are in current directory and prints:
|
0 1 2 3 4 5 6 7 8 9 |
Text files: 7 Images: 12 PDFs: 4 Total relevant files: 23 |
- Hard Write smart_greet.sh that:
- Takes one argument (name)
- If no argument → asks for name
- Prints greeting + current time of day (“Good morning/afternoon/evening”)
- Bonus: different color for morning/afternoon/evening
- Challenge Write folder_stats.sh that takes a folder path as $1 (default ~/Documents) and prints:
- Number of files
- Number of subfolders
- Biggest file (name + size in MB)
- Total size in human-readable format
How to Check Your Work
- Run each script → see output
- Compare with what you expected
- If wrong → read error → fix → try again
- Stuck > 10 min? Ask me: “Teacher, exercise 17 is not working — this is my code + this error”
Teacher’s Final Words
- Do at least 5–7 exercises from this list this week
- Keep them in ~/bash_practice/quizzes/
- When you finish one → say to yourself: “I made this work — I know this now!”
- Mistakes are good — every error teaches you something
- Celebrate small wins — even if script is only 8 lines
Which exercise do you want to start with? Or want hints for any number? Or want harder quiz next time (arrays + functions + cron together)?
Tell your Hyderabad teacher — I’m waiting! Now go — create that folder and start typing. You’ve got this! 🐧✏️🔥 😄
