see each command a script runs
Debug a script: print every command as it runs, check its syntax, find common mistakes.
shelldevelopment
steps
-
bash -x script.shrun it, printing each command first
-
set -xinside the script: print from here on; set +x stops
-
bash -n script.shcheck the syntax without running it
-
shellcheck script.shthe usual mistakes, with how to fix them (shellcheck)
commands used
bashshellcheck
Each has a page in lore: lore bash opens it.
ask for input in a script
Ask yes or no, read a password without showing it, or wait for an answer with a time limit.
check if a file or folder exists
Test in a script whether a path exists, is a file, a folder, empty or runnable.
check if a string contains a text
Test in a script whether a string contains, starts with or matches something.
find the script's own folder
Inside a script, find the folder the script is in, to reach files next to it.