From the course: Linux: Bash Shell and Scripts

Unlock the full course today

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

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

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

From the course: Linux: Bash Shell and Scripts

Start my 1-month free trial

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

- [Voiceover] Let's write a Bash script that's gonna trying usin' the eval command. So we want you to have a variable c assign the string with the quote ls -s piped in to sort -n. So ls -s will produce a list of the files with their size in front and then sort -n will sort numerically. Might be kind of handy to pipe that in detailed to see the big ones. So try running that just to saying $c and see what happens. Then try running with eval $c Then try running with eval $c and see what happens. Now let's use eval with set. So in a script assign to opts the string, a space b space \$1 space \$2. Then do set -- $opts Then do set -- $opts and echo out what your arguments are now with echo $@. So maybe we would see a b x y because when we run the script with x y z x and y are first two arguments. See what happens. Then in your script change the set to have an eval in front of it and run it again and see what you get when you echo out $@. Let's modify our options.sh script and add a couple…

Contents