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

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…

Contents