From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Debugging scripts with -x and -u options

Debugging scripts with -x and -u options

- [Instructor] Let's talk a little bit about debugging or tracing, getting a little more information about what's going on. So remember, you can run a shell program ./ the program if it has execute permission, or you can just have Bash run it, interpret it with the command bash in the name of it. Well, bash has some options you can set. So you could do bash -x when you run the program, so then it will echo out the commands after processing them so you can see a trace of what's going on. And you can do set -x inside your shell script, and to turn that off, it's set +x, so you can turn it on and off in different places in your script to just get trace information about part of the program. And if you're a little worried about syntax, you could do bash -n with the program and it'll just look for syntax errors. A handy one to set in a program is set -u. In fact, some organizations require it. So it will check to make sure you're not using a variable that hasn't been set. Remember so far…

Contents