Challenge - 5 Problems
Shell Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Understanding the purpose of a shell script
What is the main purpose of a shell script?
Attempts:
2 left
💡 Hint
Think about what you want to do when you repeat many commands often.
✗ Incorrect
A shell script is a text file containing commands that the shell can execute in order. It helps automate repetitive tasks.
💻 Command Output
intermediate1: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!"
Attempts:
2 left
💡 Hint
Look at the exact text inside the echo command.
✗ Incorrect
The echo command prints exactly what is inside the quotes, preserving case and punctuation.
📝 Syntax
advanced2: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
Attempts:
2 left
💡 Hint
Check where semicolons or newlines are needed to separate commands.
✗ Incorrect
Option B misses the semicolon or newline after '3' and before 'do', causing a syntax error.
🔧 Debug
advanced2: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"
Attempts:
2 left
💡 Hint
Check the file permissions with 'ls -l'.
✗ Incorrect
If the script file lacks execute permission, running './myscript.sh' will fail. Adding execute permission fixes this.
🚀 Application
expert2: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
Attempts:
2 left
💡 Hint
Check the value of x and the condition in the if statement.
✗ Incorrect
Since x is 5, which is greater than 3, the script prints 'Greater'.