Challenge - 5 Problems
Shebang Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this script with a shebang?
Consider this bash script saved as
What will be the output when you run
test.sh and made executable:#!/bin/bash echo "Hello from script!"
What will be the output when you run
./test.sh in a terminal?Bash Scripting
#!/bin/bash echo "Hello from script!"
Attempts:
2 left
💡 Hint
The shebang line tells the system which program to use to run the script.
✗ Incorrect
The shebang
#!/bin/bash tells the system to use bash to run the script. The echo command prints the text to the terminal.💻 Command Output
intermediate2:00remaining
What happens if the shebang line is missing?
Consider this script saved as
What will be the output when you run
myscript.sh and made executable with chmod +x myscript.sh:echo "Running script"
What will be the output when you run
./myscript.sh in a terminal?Bash Scripting
echo "Running script"Attempts:
2 left
💡 Hint
Without a shebang, the system may not know how to run the script.
✗ Incorrect
Without a shebang, the system uses the current shell to run the script, so the echo command runs and prints the text.
📝 Syntax
advanced2:00remaining
Identify the correct shebang line for bash scripts
Which of the following lines is the correct shebang to start a bash script?
Attempts:
2 left
💡 Hint
The shebang must point to the bash executable without extra arguments.
✗ Incorrect
The correct shebang for bash is exactly #!/bin/bash. Options with python or extra flags are incorrect for a simple bash script.
🔧 Debug
advanced2:00remaining
Why does this script fail to run with ./script.sh?
You have this script:
But when you run
#!/bin/bash echo "Start" exit 0
But when you run
./script.sh, you get bash: ./script.sh: Permission denied. What is the cause?Bash Scripting
#!/bin/bash echo "Start" exit 0
Attempts:
2 left
💡 Hint
Check the file permissions with ls -l.
✗ Incorrect
Permission denied means the file is not executable. Use chmod +x script.sh to fix.
🚀 Application
expert2:00remaining
How to write a portable shebang line for bash scripts?
You want your bash script to run on different systems where bash might be in different locations. Which shebang line is best to ensure portability?
Attempts:
2 left
💡 Hint
Use env to find bash in the user's PATH.
✗ Incorrect
Using #!/usr/bin/env bash runs bash from the PATH, making the script portable across systems.