UNIX & Linux converts strings into command execution
This article applies to the following topics:
Unix & Linux convert string to command
UNIX & Linux converts strings into command execution
How to convert a string to a command in Linux sh script
Answer:
Use the eval command in your shell script (this command is a built-in command for bash, and man eval is used for all bash built-in commands to view help) instead of exec.
Syntax:
Eval parameter
Parameters can be strings of a set of commands, such as "eval yum install dstat-y". If you execute eval directly without arguments, the error code is still 0 (successful execution), but it doesn't make sense.
Why not use exec?
Because exec automatically exits the current shell script after one execution, all lines after exec are ignored.
Why did exec quit automatically?
Instead of starting a new shell, exec replaces the current shell (the currently running script or login session) process with the following commands.