shellcheck FILE reads a script, without running it, and points at the lines that will break one day:
text
learner@reef:~$ shellcheck open-shop.sh
In open-shop.sh line 3:
cd ~/shops/$1
^-----------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
cd ~/shops/"$1" || exit ← the fix, ready to copy
For more information:
https://www.shellcheck.net/wiki/SC2164 -- Use 'cd ... || exit' or 'cd ... |...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...| Code | Points at | Fix |
|---|---|---|
| SC2086 | $var without quotes | "$var" |
| SC2164 | cd that is not checked | cd … || exit 1 |
| SC2162 | read without -r | read -r |
When it finds nothing, it prints nothing.
~/restock-all.sh SHOP lists a shop's low items in its restock.txt.
- Run
shellcheck restock-all.sh. Fix each finding innano ~/restock-all.sh, and run it again until it prints nothing. - Run
./restock-all.sh north. - Run
./restock-all.sh "east side".
Objectives
shellcheck restock-all.shfinds nothing.- It still works for
north. - It works for
east side.