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

Using the eval and getopt commands

Using the eval and getopt commands

- [Instructor] Let's look at a couple of kind of complicated commands, but you want to be aware of them. First one is eval. So it says bash evaluates a string. So that means the string can be a command or set variables. So it's kind of a second pass over the string so that it could be executed. You could think of it as executing data, so be careful what's in there because it could be commands that do bad things. So don't just like ask a user to type something in and then eval it. 'cause they could have typed in something you don't want. Maybe you've seen something like this. Ssh- agent -s running that. So that command is going to output these assignments to variables, and then when you eval that output, it's actually going to do those assignments of variables. If you think about it, you can't just run that and have it happen. It's going to print out those assignments. It's not going to do 'em. It's the eval that does 'em. It does the output of the command. And then we have getopt…

Contents