In the shell, if you want to get the return value of a command, if it is an integer, you can get its exit code directly with $.
But if the return value of a command is not an integer, how is it implemented?
Have to mention the command substitution function under the shell!
Two ways of implementing command substitution
Assuming that we need to get the current time for a variable, we can do this:
Date= ' Date '
Echo $date
Or you can do it.
date=$ (date)
Echo $date
Both of these methods can implement the function of command substitution, so how are they different?
The difference between two kinds of command substitution methods
1.$ () looks relatively concise, and ' easily confused ' with '.
2. In multi-layer replacement ' need to be escaped, more trouble
3. "More portability because $ () does not guarantee that all Linux systems can support
eval command
The eval command is used to tell the shell to take out the eval parameters and re-compute the parameter contents.
Like what:
Val=123
Cmd= "Echo $val 456789"
echo $cmd #echo 123 456789
Eval $cmd #123 456789
Command substitution and eval commands under the shell