From the course: Linux: Bash Shell and Scripts
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using the eval and getopt commands - Linux Tutorial
From the course: Linux: Bash Shell and Scripts
Using the eval and getopt commands
- [Instructor] The Eval command is used to get Bash to evaluate a string as a command, to make a pass over it, and expand it, and run it. It could be used when you assign to a variable some sort of command that you want to get the shell to run. You can't just say, for example, C equals this pipe command, and then dollar C. Bash gets confused by that, but if you say eval dollar C, then it expands the dollar C, and then runs that command. Now, sometimes there's some risks with using eval. If that string has got commands in it, it's going to do them, and if you accept a string from a user say, they could put commands in there that you don't want them to do, so be careful with that. You might find it helpful to read this webpage that we reference here. There's some good discussion on this page about the right way and wrong way to use eval, and the risks. The getopt command is used in your script to process command-line options. If you want your script to have dash A, dash B, and so forth,…
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 53s
-
(Locked)
Debugging scripts with -x and -u options4m
-
(Locked)
Signals and traps4m 14s
-
(Locked)
Using the eval and getopt commands6m 47s
-
(Locked)
Challenges: Debugging scripts using trap, eval, getopt, and coproc2m 49s
-
(Locked)
Solutions: Debugging scripts using trap, eval, getopt, and coproc7m 22s
-
(Locked)
-