Command substitution
In bash, $( )
and ` `
(anti-quote) are used for command substitution.
command substitution is similar to variable substitution, which is used to reorganize the command line, complete the command line in quotation marks, and then replace the result with the new command line.
$ () and '
In the operation, both are to achieve the corresponding effect, but the recommended use $( )
, for the following reasons:
- ' It's easy to mess with ', especially for beginners.
- In a multi-layered compound substitution, ' you have to have extra hops (backslashes), and $ () is more intuitive.
- Finally, the downside of $ () is that not all UNIX-like systems support this approach, but the anti-quotes are definitely supported.
# cmd1 execution result as cmd2 parameter, and then CMD2 result as cmd3 parameter Cmd3 $ (CMD2 $ (CMD1)) # If you use anti-quote, direct reference is not possible, also need to do a jump-off processing cmd3 ' cmd2 \ ' cmd1\ '
About the shell in the command to replace the $ (...) Different from the post reference ' ... '