From the course: Linux: Bash Shell and Scripts

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Debugging scripts with -x and -u options

Debugging scripts with -x and -u options - Linux Tutorial

From the course: Linux: Bash Shell and Scripts

Start my 1-month free trial

Debugging scripts with -x and -u options

- [Instructor] How can we get some debugging help with scripts? Well, we know we can run a script with the bash command, but there's some options for a bash that can help. If we do bash -x when we run a program, then bash is gonna echo out the command that's processing, so we can trace through what's goin' on. We can also turn that on or off inside the script with the set command. So if we do set -x, and run our script, from then on bash is gonna echo out the commands. And that's after it's processed them, after it's evaluated variables and so forth. Now, we can turn that off with a set +x, so we could put the set -x, set +x, around code that we're interested in tracing. If we just wanna check the syntax, like our while statements are correct, or a case statement, or anything else, or whatever, we can do bash -n, and it's just gonna check the statements. It's not gonna try to run anything. Set -u, or bash -u, will print an error message and fail if we use a variable that's unset…

Contents