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 24,700 courses taught by industry experts.

Challenge: getopt, trap, and coproc

Challenge: getopt, trap, and coproc

(upbeat music) - [Instructor] We've got some good challenges for you here. Got a bunch of 'em. So let's start out with running a Bash script where you set a variable opts equal to the string, a b \$1 \$2. And then add the line set --. When you do a set --, that's a special thing in Bash that sets the positional parameters to the sequence of values that you give it. So that will be the sequence in opts. And then in your script, echo out $@. That will print out the values of the positional parameters. So run your script with x, y, z and do you see the x and the y? That was the $1 and $2. And then, change in your program, in that set, add an eval to it, so that it has to process the stuff in there. What you're going to see is it's going to process the $1 with what the first argument was and process the $2. Run it again and see that. In the second challenge, we've got the options.sh script. Add a new option, -x and it has a long option, - -exclude, and it takes an argument and set the…

Contents