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.
Solution: Debugging scripts and using trap and eval - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Solution: Debugging scripts and using trap and eval
(upbeat music) - [Instructor] Let's look at solutions. So in our chapter four directory here, we've got challenge1.sh, and there we set c to that command string and $c, and then an eval. Let's see what happens when we run it. We get some weird error here, cannot access '|', and cannot access 'sort'. Well, when we did the $c, what happened is it really just did ls -s, and it didn't interpret the pipe, it just passed the pipe to ls, like ls was supposed to think of pipe as the name of a file to list, and sort was a name of a file to list. It didn't do the pipe stuff. But when we did the eval, then it actually did everything, and we see the output of the ls -s | and the sort -n. Let's look at when we add the -x there. So see in the top here in our shebang line, we added a -x, and maybe we can see a little better what happens. So we see it echoing the line. So we see the assignment to c, we see the ls -s, and then we see the error messages, and then we see the eval, and then we see it…
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)
-