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

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…

Contents