linux/ubuntu set:非法选项-O PipeFail

发布于 2025-01-23 16:56:22 字数 393 浏览 2 评论 0原文

以下提到的代码行一直在Ubuntu 16.04发行上使用,但突然选择 PipeFail 是一个非法选项:

set -eu -o pipefail

返回:返回:

集:非法选项-O PipeFail

为什么会发生这种情况?我在一个全新的安装系统上运行命令,作为Shell脚本的一部分。该代码在开始时放置在:

myScript.sh:

1 #!/bin/bash
2 set -eu -o pipefail
3 ...

脚本以sudo:

sudo sh ./myscript.sh

The below mentioned line of code used to work for me all the time on a Ubuntu 16.04 distribution, but suddenly option-name pipefail is an illegal option:

set -eu -o pipefail

returns:

set: Illegal option -o pipefail

Why does this happen? I run the command on a completely new installed system and as part of a shell script. The code is placed right at the beginning:

myscript.sh:

1 #!/bin/bash
2 set -eu -o pipefail
3 ...

The script is run as sudo:

sudo sh ./myscript.sh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请爱~陌生人 2025-01-30 16:56:22

您正在运行bin/sh,在ubuntu上,这是一个指向/bin/dash的符号链接,但是pipefail是一个狂欢。

使脚本可执行:

chmod +x myscript.sh

然后按以下方式运行脚本:

sudo ./myscript.sh

You are running bin/sh, on Ubuntu it is a symbolic link pointing to /bin/dash, but pipefail is a bashism.

Make the script executable:

chmod +x myscript.sh

and then run the script as follows:

sudo ./myscript.sh
感情废物 2025-01-30 16:56:22

zsh运行脚本时,我遇到了相同的错误,并且脚本以不正确 shebang开始。

错误,缺少 <代码>#:

#/bin/bash
rest-of-the-script

正确:

#!/bin/bash
rest-of-the-script

I had the same error when running script from zsh and the script began with incorrect shebang.

WRONG, missing ! after #:

#/bin/bash
rest-of-the-script

Correct:

#!/bin/bash
rest-of-the-script
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文