ShellCheck is a tool that checks shell scripts for common mistakes and potential bugs before running them. It helps you write safer and cleaner scripts.
Click to reveal answer
beginner
How does ShellCheck help beginners?
ShellCheck points out errors and warnings in your script with clear messages. It explains what might go wrong and suggests how to fix it, like a friendly script coach.
Click to reveal answer
beginner
Which command runs ShellCheck on a script named myscript.sh?
You run: shellcheck myscript.sh. This checks the script and shows any issues found.
Click to reveal answer
intermediate
What kind of problems can ShellCheck detect?
ShellCheck finds syntax errors, unsafe variable use, quoting mistakes, unused variables, and common pitfalls that can cause your script to fail or behave unexpectedly.
Click to reveal answer
beginner
Why is static analysis useful before running scripts?
Static analysis checks your code without running it. This means you can catch bugs early, avoid crashes, and save time debugging later.
Click to reveal answer
What does ShellCheck primarily do?
AChecks shell scripts for errors before running
BRuns shell scripts faster
CConverts shell scripts to Python
DFormats shell scripts with colors
✗ Incorrect
ShellCheck analyzes shell scripts to find errors and warnings before execution.
How do you use ShellCheck on a script named script.sh?
Abashcheck script.sh
Brun script.sh
Ccheck script.sh
Dshellcheck script.sh
✗ Incorrect
The correct command is shellcheck script.sh to analyze the script.
Which problem is NOT typically detected by ShellCheck?
AUnsafe variable use
BNetwork connectivity issues
CSyntax errors
DQuoting mistakes
✗ Incorrect
ShellCheck does not check runtime issues like network connectivity.
Why is quoting variables important in shell scripts?
ATo make scripts run faster
BTo change variable values
CTo prevent word splitting and errors
DTo comment out code
✗ Incorrect
Quoting variables prevents unexpected splitting and errors in scripts.
What type of tool is ShellCheck?
AStatic analysis tool
BDebugger
CCode formatter
DPackage manager
✗ Incorrect
ShellCheck is a static analysis tool that checks code without running it.
Explain what ShellCheck does and why it is helpful for shell scripting.
Think about how checking your work before running saves time and prevents mistakes.
You got /4 concepts.
Describe common mistakes in shell scripts that ShellCheck can detect.
Consider errors that cause scripts to fail or behave unexpectedly.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using ShellCheck in shell scripting?
easy
A. To find errors and suggest fixes before running the script
B. To execute the script faster
C. To convert shell scripts to Python
D. To add colors to the terminal output
Solution
Step 1: Understand what ShellCheck does
ShellCheck is a tool that analyzes shell scripts without running them to find mistakes.
Step 2: Identify the main benefit
It helps catch errors early, like missing quotes or bad syntax, making scripts safer.
Final Answer:
To find errors and suggest fixes before running the script -> Option A
Quick Check:
ShellCheck finds errors [OK]
Hint: ShellCheck checks scripts for errors before execution [OK]
Common Mistakes:
Thinking ShellCheck runs the script
Believing it speeds up script execution
Confusing it with a code converter
2. Which of the following is the correct way to run ShellCheck on a script named myscript.sh?
easy
A. bash shellcheck myscript.sh
B. checkshell myscript.sh
C. run shellcheck myscript.sh
D. shellcheck myscript.sh
Solution
Step 1: Recall the ShellCheck command syntax
The correct command to run ShellCheck is simply shellcheck followed by the script name.
Step 2: Verify the options
Options B, C, and D use incorrect command names or extra words.
Final Answer:
shellcheck myscript.sh -> Option D
Quick Check:
Use 'shellcheck scriptname' [OK]
Hint: Use 'shellcheck' command followed by script name [OK]
Common Mistakes:
Typing 'checkshell' instead of 'shellcheck'
Adding extra words like 'run' before the command
Using 'bash shellcheck' which is invalid
3. Given this script echo Hello $name and running shellcheck script.sh, what warning will ShellCheck most likely show?
medium
A. SC1000: Syntax error near unexpected token.
B. SC2001: Use 'sed' instead of 'echo'.
C. SC2086: Double quote to prevent globbing and word splitting.
D. No warnings, script is perfect.
Solution
Step 1: Understand ShellCheck's common warnings
ShellCheck warns when variables are unquoted because it can cause word splitting or globbing.
Step 2: Match warning to the script
The script uses $name without quotes, so ShellCheck will warn about missing quotes (SC2086).
Final Answer:
SC2086: Double quote to prevent globbing and word splitting. -> Option C
Quick Check:
Unquoted variables cause SC2086 warning [OK]
Hint: Look for unquoted variables to spot SC2086 warnings [OK]
Common Mistakes:
Expecting syntax errors for simple echo
Thinking no warning appears for unquoted variables
Confusing warning codes with unrelated messages
4. You have this script snippet:
if [ $count -eq 10 ]; then
echo "Count is 10"
fi
ShellCheck reports an error. What is the best fix?
medium
A. Add quotes around $count: if [ "$count" -eq 10 ]; then
B. Remove the spaces inside [ ]
C. Change -eq to ==
D. Add a semicolon after echo statement
Solution
Step 1: Identify the ShellCheck warning cause
Using $count without quotes can cause errors if $count is empty or contains spaces.
Step 2: Apply the fix
Adding quotes around $count ensures the test works safely even if the variable is empty.
Final Answer:
Add quotes around $count: if [ "$count" -eq 10 ]; then -> Option A