什么是“ -xe”是什么Shell脚本中的Shebang(#!/bin/bash)代表?
我已经复制了一个shell脚本,这很简单,但是在Shebang的第一行中,指定了-Xe
标志。
#!/bin/bash -xe
谁能解释它做什么?我已经搜索过,但找不到任何帮助材料。
I have copied a shell script and it is pretty much simple but on the first line with shebang, the -xe
flag is specified.
#!/bin/bash -xe
Can anyone explain what does it do? I have searched but could not find any helping material.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在Shebang中添加Shell选项:
-X
,-O Xtrace
:跟踪显示执行的语句。-e
,-o errexit
:错误时退出,但不一致,但对于旧版POSIX的遵守情况而言不一致。这种Shebang设置将两种灰心的做法与自己的一系列问题结合在一起:
bash script_name
,而不是使脚本文件可执行,并调用./ script_name
。选项应用
set -x
在代码中明确设置,或者最好使用其更简单的长名称(示例:set -o xtrace
而不是set set -x < /代码>)。
-e
选项或set -o errexit
,它仅用于旧版POSIX遵守,但在不同情况下的行为如此不一致;它导致的错误比避免的错误更多。以下是有关这些
set -e
,set -o errexit
Quirks and Issess的一些引用:This is adding shell options to the shebang:
-x
,-o xtrace
: Trace display executed statements.-e
,-o errexit
: Exit on error, but inconsistently for legacy POSIX compliance.This shebang setting combines two discouraged bad practices with their own set of issues:
bash script_name
, rather than making the script file executable, and invoking./script_name
.Options shall be set explicitly in code with
set -x
, or preferably use their more straightforward long name (example:set -o xtrace
instead ofset -x
).-e
option orset -o errexit
which is only there for legacy POSIX compliance, but acts so inconsistently in different situations; that it causes more bugs than it avoids.Here are some references about those
set -e
,set -o errexit
quirks and issues: