https://stackoverflow.com/questions/951336/how-to-debug-a-bash-script sh -x script [arg1 ...] bash -x script [arg1 ...] These give you a trace of what is being executed. (See also 'Clarification' near the bottom of the answer.) (-v makes it verbose) Sometimes, you need to control the debugging within the script. In that case, as Cheeto reminded me, you can use: set -x This turns debugging on. You can then turn it off again with: set +x (You can find out the current tracing state by analyzing $-, the current flags, for x.) set -e makes the script stop immediately if any external program returns a non-zero exit status. This is useful if your script attempts to handle all error cases and where a failure to do so should be trapped. set -n might also be useful if you want to check your script for syntax errors. strace is also useful to see what's going on. Especially useful if you haven't written the script yourself.