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 - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
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…
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)
-