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 - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Using the coproc command5m 22s
-
(Locked)
Debugging scripts with -x and -u options3m 12s
-
(Locked)
Signals and traps2m 38s
-
(Locked)
Using the eval and getopt commands3m 57s
-
(Locked)
Challenge: Debugging scripts and using trap and eval1m 21s
-
(Locked)
Solution: Debugging scripts and using trap and eval2m 8s
-
(Locked)
Challenge: getopt, trap, and coproc3m 4s
-
(Locked)
Solution: getopt, trap, and coproc4m 13s
-
(Locked)
-