From the course: Linux: Bash Shell and Scripts

Unlock the full course today

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

Solutions: Debugging scripts using trap, eval, getopt, and coproc

Solutions: Debugging scripts using trap, eval, getopt, and coproc - Linux Tutorial

From the course: Linux: Bash Shell and Scripts

Start my 1-month free trial

Solutions: Debugging scripts using trap, eval, getopt, and coproc

(chime) - [Instructor] So, for the first challenge let's see what we've got. We assigned a c, that command with the pipe in it, and we try to run it with just $c, then we try to run it with eval $c. So, if we run it, we see we get a weird error there. Cannot access pipe, no such file or directory. Cannot access sort, no such file or directory. So, what happened when we did $c, is it didn't process the pipe symbol. It just passed that along to the LS command. But when we did the eval, it worked. 'Cause when we did the eval, the shell processed the $c and broke it up into the LS and sort commands with the pipe. So, if you're going to assign a variable, a command that's kind of tricky, like with pipes in it, or stuff you need the shell to evaluate, you need to do eval. For the second challenge, we want to look at the option processing with set. So, with this version, we've got just a set and we've got commented out the eval. If we run this, with x y z we see options are a b $1 $2. It…

Contents