bash Shell 命令 SET -X 在脚本中的意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52663302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Shell command SET -X mean in script
提问by Alok
So I have a file deploy.sh, and it has the shell script. Since I know about it, I have a little confusion, that is what does that set -x
actually means.
所以我有一个文件deploy.sh,它有 shell 脚本。既然我知道,我有点困惑,这就是它的set -x
实际含义。
After running the file I have observed that the command written after it in the file gets mentioned in the terminal with a +sign.
运行该文件后,我观察到在文件中写入它之后的命令在终端中用+号提及。
Like if I have this,
就像如果我有这个
#!/bin/bash
set -x
ng build
So the output mentions +ng build
, and when I comment the set -x
from the file, everything executes, but the later commands does not show up in the terminal.
所以输出提到了+ng build
,当我set -x
从文件中评论时,一切都会执行,但后面的命令没有显示在终端中。
I have researched about it, but specifically couldn't find the real meaning and work of this particular command.
我已经研究过它,但特别找不到这个特定命令的真正含义和工作。
回答by Würgspa?
You can read the bash
online manualfor set
:
你可以阅读bash
在线手册为set
:
-x
Print a trace of simple commands, for commands, case commands, select commands, and arithmetic for commands and their arguments or associated word lists after they are expanded and before they are executed. The value of the PS4 variable is expanded and the resultant value is printed before the command and its expanded arguments.
-X
在扩展之后和执行之前,打印简单命令的踪迹,用于命令、case 命令、选择命令和命令及其参数的算术或关联的单词列表。PS4 变量的值被扩展,结果值打印在命令及其扩展参数之前。
So it does exactly what you described.
所以它完全符合你的描述。
回答by Alfe
It's a bit hard to find but this is from the bash man page:
有点难找到,但这是来自 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
, , ... $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.
So basically it's a debug option. It does not only execute all the commands but also prints them before it executes them (to stderr).
所以基本上它是一个调试选项。它不仅执行所有命令,而且在执行它们之前打印它们(到 stderr)。