0
0
Bash Scriptingscripting~20 mins

ShellCheck for static analysis in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ShellCheck Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What does ShellCheck report for this script?
Given the following Bash script, what warning or error will ShellCheck produce?
Bash Scripting
echo "User input is: $1"
if [ $1 -eq 10 ]; then
  echo "Input is ten"
fi
ASC1009: The mentioned syntax error was in this if statement.
BNo warnings, script is clean.
CSC2086: Double quote to prevent globbing and word splitting.
DSC2154: $1 is referenced but not assigned.
Attempts:
2 left
💡 Hint
ShellCheck often warns about unquoted variables in test conditions.
📝 Syntax
intermediate
2:00remaining
Which script will pass ShellCheck without errors?
Select the Bash script snippet that will NOT produce any ShellCheck warnings or errors.
Afor file in *.txt; do echo ${file}; done; echo $file
Bfor file in *.txt; do echo "$file"; done
Cfor file in *.txt; do echo ${file}; done
Dfor file in *.txt; do echo $file; done
Attempts:
2 left
💡 Hint
ShellCheck warns about unquoted variables that may cause word splitting.
🔧 Debug
advanced
2:00remaining
Identify the ShellCheck warning for this script
What specific ShellCheck warning will this script produce?
Bash Scripting
#!/bin/bash

read -p "Enter your name: " name
if [ "$name" = "" ]; then
  echo "No name entered"
fi
ASC2143: Use grep -q instead of comparing output with -eq.
BNo warnings, script is clean.
CSC2006: Use $(...) instead of backticks.
DSC2162: read without -r will mangle backslashes.
Attempts:
2 left
💡 Hint
ShellCheck warns about read command usage without -r option.
🧠 Conceptual
advanced
2:00remaining
Why does ShellCheck warn about this variable usage?
Consider this snippet: filename=$1 if [ -f $filename ]; then echo "File exists" fi Why does ShellCheck warn about the test condition?
ABecause $filename is unquoted, it may cause word splitting or globbing issues.
BBecause $filename is not declared as a local variable.
CBecause -f test requires an absolute path, not a variable.
DBecause the if statement syntax is incorrect.
Attempts:
2 left
💡 Hint
Think about what happens if the filename contains spaces.
🚀 Application
expert
2:00remaining
What is the output of running ShellCheck on this script?
Given this script: #!/bin/bash for i in {1..3} do echo "Number: $i" done What output will ShellCheck produce?
ANo warnings or errors, script is clean.
BSC2034: i appears unused in the loop.
CSC1009: Syntax error near unexpected token '{1..3}'.
DSC2086: Double quote to prevent globbing and word splitting.
Attempts:
2 left
💡 Hint
Brace expansion is valid in Bash and commonly used in loops.