This article applies to the following topics:
Unix & Linux Convert string to command
UNIX & Linux Convert strings to command execution
How to convert a string into a command in a Linux sh script
Answer:
Use the eval command in a shell script (this command is Bash's built-in command, which is used when Bash's built-in commands view help with man Eval), not exec.
Grammar:
Eval parameters
Parameters can be strings for a set of commands, such as "eval yum install Dstat–y", if you do not add parameters directly to Eval can also, return error code is still 0 (successful execution), but meaningless.
Why not exec?
Because exec exits the current shell script automatically after execution, all rows after exec are ignored.
Why does exec automatically quit?
exec does not start a new shell, but instead replaces the current shell (the currently running script or login session) with the command that follows it.
This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1537282