命令中命令的术语 $( ... )

命令中命令的术语 $( ... )

我有一个脚本update-wallpaper,有点像这样:

ln -s $(get-wallpaper-path) ~/.config/bg-manager/wallpaper

该表达$( ... )被称为...某事...并且$()在 Google 和 Bing 上搜索该符号没有给出任何结果。

虽然“内联命令”这个短语听起来不错,但它看起来不像是官方术语——至少对于我最喜欢的搜索引擎来说是这样。 “官方”短语是什么?

答案1

$(您可以通过在 Bash页面中搜索来在本地计算机上获取此信息man

tomas@tomas-Latitude-E4200:~$ man bash | grep -A2 -B2 '$('
       If value is not given, the variable is assigned the null string.  All values undergo tilde expansion, parameter and variable expansion, command sub‐
       stitution, arithmetic expansion, and quote removal (see EXPANSION below).  If the variable has its integer attribute set, then value is evaluated as
       an  arithmetic  expression  even  if the $((...)) expansion is not used (see Arithmetic Expansion below).  Word splitting is not performed, with the
       exception of "$@" as explained below under Special Parameters.  Pathname expansion is not performed.  Assignment statements may also appear as argu‐
       ments  to  the  alias,  declare,  typeset, export, readonly, and local builtin commands.  When in posix mode, these builtins may appear in a command
--
       Command substitution allows the output of a command to replace the command name.  There are two forms:

              $(command)
       or
              `command`

       Bash  performs  the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing
       newlines deleted.  Embedded newlines are not deleted, but they may be removed during word splitting.  The command substitution $(cat  file)  can  be
       replaced by the equivalent but faster $(< file).

       When  the  old-style  backquote  form  of substitution is used, backslash retains its literal meaning except when followed by $, `, or \.  The first
       backquote not preceded by a backslash terminates the command substitution.  When using the $(command) form, all characters between  the  parentheses
       make up the command; none are treated specially.

--
       Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result.  The format for arithmetic expansion is:

              $((expression))

       The old format $[expression] is deprecated and will be removed in upcoming versions of bash.

可能需要对-A-B参数进行一些调整。这些设置前后上下文,并取决于man页面本身、其中的内容以及终端显示 - 每行显示多少个字符。所以你需要看看你所看到的并思考你想看到的。

但结果可能是有益的。这是第一个清单的关键摘录:

       Command substitution allows the output of a command to replace the command name.  There are two forms:

              $(command)
       or
              `command`

相关内容