Debugging a bash shell script

Run a shell script with -x option

$ bash -x script-name
$ bash -x shell-script.sh

Use a set builtin command

set -x : Display commands and their arguments as they are executed.
set -v : Display shell input lines as they are read

i.e. in bash-script.sh
#!/bin/bash -xv

OR
set -x #turn on debug mode
set _x #turn off debug mode
  •  
  •  
  •  
  •  

Viet Luu has written 318 articles

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

We are thankful for your never ending support.

Leave a Reply