Challenge - 5 Problems
Bash Style Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this script regarding variable naming?
Consider this bash script snippet that follows common style conventions for variable names. What will be the output?
Bash Scripting
MY_VAR=5 my_var=10 echo "$MY_VAR $my_var"
Attempts:
2 left
💡 Hint
Variable names in bash are case-sensitive.
✗ Incorrect
In bash, variable names are case-sensitive. MY_VAR and my_var are two different variables. MY_VAR is assigned 5, my_var is assigned 10, so echo prints '5 10'.
📝 Syntax
intermediate1:30remaining
Which option correctly follows the style guide for function definitions in bash?
Select the function definition that follows common bash style conventions for readability and compatibility.
Attempts:
2 left
💡 Hint
The preferred style avoids the 'function' keyword and places parentheses immediately after the function name.
✗ Incorrect
The recommended style for bash functions is 'name() { ... }' without the 'function' keyword for better portability and clarity.
🔧 Debug
advanced2:00remaining
Identify the style violation causing the script to fail in strict mode
This script fails when run with 'set -u' (treat unset variables as errors). What style issue causes this failure?
Bash Scripting
echo "User: $USER_NAME" if [ "$USER_NAME" = "admin" ]; then echo "Welcome admin" fi
Attempts:
2 left
💡 Hint
Strict mode requires variables to be initialized before use.
✗ Incorrect
Using 'set -u' causes an error if a variable is used before being set. The style guide recommends initializing variables to avoid this error.
🧠 Conceptual
advanced1:30remaining
Why is it recommended to use lowercase variable names for local variables in bash scripts?
Choose the best explanation for why local variables in bash scripts are often named in lowercase.
Attempts:
2 left
💡 Hint
Think about environment variables and naming conventions.
✗ Incorrect
Environment variables and system variables are usually uppercase. Using lowercase for local variables avoids accidental overwriting and confusion.
🚀 Application
expert2:00remaining
What is the output of this script following style conventions for quoting and command substitution?
Analyze the script and select the correct output. The script uses recommended style for quoting and command substitution.
Bash Scripting
files_count=$(ls -1 | wc -l) echo "Number of files: $files_count"
Attempts:
2 left
💡 Hint
Command substitution captures the output of the command inside $(...).
✗ Incorrect
The command substitution $(ls -1 | wc -l) runs the commands and stores the output (number of files) in files_count. The echo prints the number.