To debug a script you may: Add -x to interpreter line: #!/usr/bin/sh -x Put command: set -x close to the section of interest In suitable places, put "echo $VARIABLE" or "sleep 30" or similar statments to trace values or to give time for checking output. In pipelines put "tee debugfile" to check if data going down pipeline is what you expect. Note the following coding problems which often cause problems: There is no white space around = on variable assignment. The arguments to all commands, inparticular, to test ([) must be space separated. ; is required between commands on the same line ;; is used in case statements to terminal statements matching a pattern When a VARIABLE could contain characters significant to the shell quote the value: "$VARIABLE" is usually best.