From the course: Linux: Bash Shell and Scripts

Unlock the full course today

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

Using the eval and getopt commands

Using the eval and getopt commands - Linux Tutorial

From the course: Linux: Bash Shell and Scripts

Start my 1-month free trial

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,…

Contents