Challenge - 5 Problems
Bash Script Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Bash script?
Consider this simple Bash script that prints a greeting message. What will it output when run?
Bash Scripting
#!/bin/bash name="Alice" echo "Hello, $name!"
Attempts:
2 left
💡 Hint
Look at how variables are used with the $ sign inside double quotes.
✗ Incorrect
The variable 'name' is set to 'Alice'. Using $name inside double quotes expands to its value, so echo prints 'Hello, Alice!'.
💻 Command Output
intermediate2:00remaining
What does this Bash script print?
This script uses a loop to print numbers. What is the output?
Bash Scripting
#!/bin/bash for i in {1..3}; do echo $i done
Attempts:
2 left
💡 Hint
The loop runs from 1 to 3 inclusive, printing each number on its own line.
✗ Incorrect
The for loop iterates over 1, 2, and 3, echoing each number on a new line.
📝 Syntax
advanced2:00remaining
Which option contains a syntax error in this Bash script?
Identify the option that will cause a syntax error when running the script.
Bash Scripting
#!/bin/bash count=5 if [ $count -gt 3 ]; then echo "Count is greater than 3" fi
Attempts:
2 left
💡 Hint
Check if the 'then' keyword is present after the if condition.
✗ Incorrect
Option B is missing the 'then' keyword after the if condition, causing a syntax error.
💻 Command Output
advanced2:00remaining
What is the output of this script using command substitution?
This script stores the current date in a variable and prints it. What will it output?
Bash Scripting
#!/bin/bash current_date=$(date +"%Y-%m-%d") echo "Today is $current_date"
Attempts:
2 left
💡 Hint
The $(...) syntax runs the command inside and replaces it with its output.
✗ Incorrect
The date command outputs the current date in YYYY-MM-DD format, which is stored in current_date and printed.
🚀 Application
expert2:00remaining
How many lines will this script output?
This script reads a file line by line and counts lines containing 'error'. How many lines will it print?
Bash Scripting
#!/bin/bash count=0 while IFS= read -r line; do if [[ $line == *"error"* ]]; then ((count++)) fi done < input.txt echo $count
Attempts:
2 left
💡 Hint
If the file input.txt does not exist, the script will fail.
✗ Incorrect
If input.txt is missing, the script cannot read lines and will produce an error.