A worked example, rendered from real sample data. Sign in to run the tool on your own input.
#!/bin/bash
cd /opt/app
DIR=$HOME/data
if [ $DIR == "/root" ]; then
rm -rf /tmp/*
fi
which pythonShell: bash (from #!/bin/bash)
Lines: 7 · strict mode: missing
Findings: 0 error, 4 warning, 3 info
WARNING (4)
2:1 [SC2164] `cd` is unchecked — if it fails the script keeps running in the wrong directory.
→ Use `cd dir || exit 1`, or turn on `set -e`.
- cd /opt/app
+ cd /opt/app || exit 1
4:6 [SC2086] $DIR is unquoted, so the value word-splits and globs.
→ Wrap every expansion in double quotes: "$VAR".
- if [ $DIR == "/root" ]; then
+ if [ "$DIR" == "/root" ]; then
4:11 [SC2039] `==` inside single-bracket `[ ]` is a bashism — POSIX `test` only knows `=`.
→ Use `[ "$a" = "$b" ]`, or switch the whole test to `[[ … == … ]]` in bash.
- if [ $DIR == "/root" ]; then
+ if [ $DIR = "/root" ]; then
5:10 `rm -rf /tmp/*` recursively deletes everything the glob matches under an absolute path.
→ Double-check the path, and prefer `find … -delete` with explicit constraints.
- rm -rf /tmp/*
INFO (3)
2:1 No `set -euo pipefail` — the script keeps going after a failed command and silently accepts unset variables.
→ Add `set -euo pipefail` right after the shebang.
+ set -euo pipefail
4:4 Single-bracket `[ ]` is used — in bash, `[[ ]]` is the safer form.
→ `[[ ]]` never word-splits its operands and supports `&&`, `||` and pattern matching.
- if [ $DIR == "/root" ]; then
7:1 [SC2230] `which` is an external, non-standard program with inconsistent exit codes.
→ Use the shell builtin `command -v` instead.
- which python
+ command -v python
Lint shell scripts for shellcheck-style issues and get the corrected lines. Part of the DevTools Surf developer suite. Browse more tools in the Developer Utilities collection.