【问题标题】:Shell command SET -X mean in script [duplicate]Shell命令SET -X在脚本中的意思[重复]
【发布时间】:2019-10-24 21:28:08
【问题描述】:

所以我有一个文件 deploy.sh,它有 shell 脚本。既然我知道,我有点困惑,这就是set -x 的真正含义。

运行文件后,我观察到在文件中写入的命令在终端中被提及,并带有 + 符号。

如果我有这个,

#!/bin/bash
set -x

ng build

所以输出提到了+ng build,当我从文件中注释set -x 时,一切都会执行,但后面的命令不会显示在终端中。

我对此进行了研究,但具体找不到这个特定命令的真正含义和工作。

【问题讨论】:

    标签: bash sh


    【解决方案1】:

    您可以阅读bash online manual for set

    -x

    打印简单命令的痕迹,对于命令,case命令,select 命令,以及命令及其参数的算术或 相关单词列表在它们展开之后和之前 执行。 PS4 变量的值被展开,结果 value 在命令及其扩展参数之前打印。

    所以它和你描述的完全一样。

    【讨论】:

      【解决方案2】:

      有点难找,但这是来自 bash 手册页:

         set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...]
                Without options, the name and value of each shell  variable  are
                displayed in a format that can be reused as input for setting or
                resetting the currently-set variables.  Read-only variables can‐
                not  be  reset.  In posix mode, only shell variables are listed.
                The output is sorted according  to  the  current  locale.   When
                options  are specified, they set or unset shell attributes.  Any
                arguments remaining after option processing are treated as  val‐
                ues for the positional parameters and are assigned, in order, to
                $1, $2, ...  $n.  Options,  if  specified,  have  the  following
                meanings:
                [...]
                -x      After expanding each simple command, for  command,  case
                        command, select command, or arithmetic for command, dis‐
                        play the expanded value of PS4, followed by the  command
                        and its expanded arguments or associated word list.
      

      所以基本上它是一个调试选项。它不仅执行所有命令,而且在执行它们之前打印它们(到 stderr)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-17
        • 2014-11-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多