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 25,300 courses taught by industry experts.
Challenge: Debugging scripts and using trap and eval - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Challenge: Debugging scripts and using trap and eval
(electronic music) - [Instructor] All right, we're getting down to it here. We got some more challenges. In fact, we got so many, we broke it up into a couple different movies. So the first one here, you need to write a Bash script that assigns to a variable c, the value ls -s | sort -n. So in C is that command that's got a pipe in it. Then in your script, just say $c, like it's a command, and see what happens. Does it run that command? Then in your script after that, do eval $c. So we can see the difference between just $c with a command in it versus eval with a command in it. And then after doing that, think about what are the risks of doing an eval on a variable. You know, what could be in that variable that might be a problem. Then for a second one here, in that script on the shebang line where you did pound bang bin bash, add at the end space -x. So it's going to set the X mode. It's going to be running bash dash x, and then run the script again and look at what that -x did…
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)
-