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

  1. No peeking at previous messages or Google for the first attempt
  2. Time yourself — try to finish in 20–30 minutes
  3. Write answers in a text file or on paper — don’t just think
  4. For coding questions — actually type & run the code in terminal
  5. After finishing → check my answers & explanations below
  6. 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)

  1. What is the correct way to assign a variable? a) name = “Rahul” b) name=”Rahul” c) $name = “Rahul” d) name =Rahul
  2. Which of these will correctly print the value of variable $city? a) echo $city b) echo ‘$city’ c) echo “$city” d) echo {city}
  3. What does this line do? today=$(date +%Y-%m-%d)
  4. 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[*]
  5. Which test syntax is modern & recommended? a) [ “$a” == “yes” ] b) [[ “$a” == “yes” ]] c) (( “$a” == “yes” )) d) test “$a” = “yes”
  6. What is the correct numeric “greater than” operator inside [[ ]]? a) > b) -gt c) gt d) >=
  7. How do you make a variable local inside a function? a) var=”value” b) local var=”value” c) VAR=”value” d) export var=”value”
  8. What does */10 * * * * mean in crontab? a) Every 10 seconds b) Every 10 minutes c) Every 10 hours d) Every 10th day
  9. 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
  10. What is the shebang line? Write it correctly.

Part B – Spot the Mistake (Find & Fix)

Bash
Bash
Bash
Bash
Bash

Part C – Write Mini-Scripts (Type & Run These)

  1. 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!”
  1. Medium Write backup_today.sh that:
  • Creates backup name Documents_YYYY-MM-DD.tar.gz
  • Backs up only ~/Documents
  • Prints success or error message
  1. Medium-Hard Write count_by_ext.sh that counts how many .txt, .jpg/.png, .pdf files are in current directory and prints:
text
  1. 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
  1. 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! 🐧✏️🔥 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *