Bird
Raised Fist0
Bash Scriptingscripting~20 mins

What a shell script is in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Shell Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the purpose of a shell script
What is the main purpose of a shell script?
ATo automate tasks by running a series of commands in sequence
BTo compile source code into executable programs
CTo create graphical user interfaces for applications
DTo store data in a structured database format
Attempts:
2 left
💡 Hint
Think about what you want to do when you repeat many commands often.
💻 Command Output
intermediate
1:30remaining
Output of a simple shell script
What will be the output when running this shell script? #!/bin/bash echo "Hello, friend!"
Bash Scripting
#!/bin/bash
 echo "Hello, friend!"
AError: command not found
Bhello, friend!
CHELLO, FRIEND!
DHello, friend!
Attempts:
2 left
💡 Hint
Look at the exact text inside the echo command.
📝 Syntax
advanced
2:00remaining
Identifying a syntax error in a shell script
Which option contains a syntax error in this shell script snippet? for i in 1 2 3 do echo $i done
Bash Scripting
for i in 1 2 3
 do
 echo $i
 done
Afor i in 1 2 3; do echo $i; done
Bfor i in 1 2 3 do echo $i done
C
for i in 1 2 3
do echo $i
done
Dfor i in 1 2 3; do echo $i done
Attempts:
2 left
💡 Hint
Check where semicolons or newlines are needed to separate commands.
🔧 Debug
advanced
2:00remaining
Why does this shell script fail to run?
This shell script is saved as 'myscript.sh' but fails to run with './myscript.sh'. What is the likely reason? #!/bin/bash echo "Running script"
AThe script file does not have execute permission
BThe shebang line is incorrect
CThe echo command is misspelled
DThe script must be run with 'bash myscript.sh' only
Attempts:
2 left
💡 Hint
Check the file permissions with 'ls -l'.
🚀 Application
expert
2:30remaining
Determining the output of a shell script with variables and conditionals
What is the output of this shell script? #!/bin/bash x=5 if [ $x -gt 3 ]; then echo "Greater" else echo "Smaller" fi
Bash Scripting
#!/bin/bash
 x=5
 if [ $x -gt 3 ]; then
   echo "Greater"
 else
   echo "Smaller"
 fi
ASyntax error
BSmaller
CGreater
DNo output
Attempts:
2 left
💡 Hint
Check the value of x and the condition in the if statement.

Practice

(1/5)
1. What is a shell script in simple terms?
easy
A. A file containing commands that run automatically in the shell
B. A program that only runs on Windows
C. A type of hardware device
D. A graphical user interface for the computer

Solution

  1. Step 1: Understand what a shell script is

    A shell script is a text file with commands that the shell can run automatically.
  2. Step 2: Compare options to definition

    Only A file containing commands that run automatically in the shell describes a file with commands running automatically in the shell.
  3. Final Answer:

    A file containing commands that run automatically in the shell -> Option A
  4. Quick Check:

    Shell script = file with commands [OK]
Hint: Think: script means commands saved to run later [OK]
Common Mistakes:
  • Confusing shell script with software programs
  • Thinking shell scripts are hardware
  • Believing shell scripts are graphical tools
2. Which of these is the correct way to start a shell script file?
easy
A.
B. #!/bin/bash
C. print('Hello World')
D. function main() {}

Solution

  1. Step 1: Identify the shell script shebang

    The first line in a shell script usually starts with #!/bin/bash to tell the system to use bash shell.
  2. Step 2: Check other options

    <!DOCTYPE html> is for HTML, print('Hello World') is Python, function main() {} is like JavaScript. None are shell script shebangs.
  3. Final Answer:

    #!/bin/bash -> Option B
  4. Quick Check:

    Shell scripts start with #!/bin/bash [OK]
Hint: Look for #! to start shell scripts [OK]
Common Mistakes:
  • Using code from other languages as shell script start
  • Omitting the shebang line
  • Confusing shell script with HTML or Python
3. What will this shell script output?
#!/bin/bash
echo "Hello, World!"
medium
A. Error: command not found
B. echo "Hello, World!"
C. No output
D. Hello, World!

Solution

  1. Step 1: Understand the echo command

    The echo command prints the text inside quotes to the screen.
  2. Step 2: Predict the output

    The script will print exactly: Hello, World!
  3. Final Answer:

    Hello, World! -> Option D
  4. Quick Check:

    echo prints text = Hello, World! [OK]
Hint: echo prints text exactly as given [OK]
Common Mistakes:
  • Thinking echo prints the command itself
  • Expecting error without cause
  • Assuming no output without running script
4. This shell script is supposed to print "Done" but it shows an error:
#!/bin/bash
echo Done

What is the likely problem?
medium
A. The shebang line is incorrect
B. The echo command is misspelled
C. The script file is missing execute permission
D. The script needs a semicolon after echo

Solution

  1. Step 1: Check script permissions

    If the script shows an error when run, it might not have execute permission set.
  2. Step 2: Verify other options

    Echo is correct, shebang is correct, and semicolon is not needed after echo.
  3. Final Answer:

    The script file is missing execute permission -> Option C
  4. Quick Check:

    Missing execute permission causes errors [OK]
Hint: Make script executable with chmod +x [OK]
Common Mistakes:
  • Assuming syntax error without checking permissions
  • Adding unnecessary semicolons
  • Changing correct shebang line
5. You want to automate cleaning temporary files daily using a shell script. Which statement best describes what you should do?
hard
A. Write a shell script with commands to delete temp files, then schedule it with cron
B. Manually type delete commands every day in the terminal
C. Use a graphical tool only, no scripts needed
D. Write a shell script but run it only once manually

Solution

  1. Step 1: Understand automation goal

    To automate daily cleaning, you need a script that runs commands automatically.
  2. Step 2: Use scheduling tool

    Cron is a tool that runs scripts on a schedule, perfect for daily tasks.
  3. Final Answer:

    Write a shell script with commands to delete temp files, then schedule it with cron -> Option A
  4. Quick Check:

    Script + cron = daily automation [OK]
Hint: Combine script with cron for daily tasks [OK]
Common Mistakes:
  • Thinking manual typing is automation
  • Ignoring scheduling tools like cron
  • Running script only once instead of daily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard