小编nyx*_*x19的帖子

无法使用 set -eo pipefail 在管道中成功调用任何外部 shell 脚本

假设以下test-pipefail.sh批处理:

#!/usr/bin/env bash
set -eo pipefail
./echoer.sh | head -n1 >/dev/null
echo "Might work with pipefail"
for i in {1..100} ; do
    ./echoer.sh | head -n1 >/dev/null
done
echo "Stable work with pipefail"
Run Code Online (Sandbox Code Playgroud)

使用echoer.sh内容:

#!/usr/bin/env bash
echo 'head (GNU coreutils) 8.30'
echo 'GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)'
exit 0
Run Code Online (Sandbox Code Playgroud)

./test-pipefail.sh 的预期结果:

Might work with pipefail
Stable work with pipefail
Run Code Online (Sandbox Code Playgroud)

实际行为:

Might work with pipefail
Run Code Online (Sandbox Code Playgroud)

或(随机)没有输出。

如果我使用任何二进制实用程序而不是echoer.sh,管道中的 Writer 程序永远不会失败,但如果 writer 是 shell 脚本(例如,来自 glibc …

linux bash shell pipe built-in

3
推荐指数
2
解决办法
198
查看次数

标签 统计

bash ×1

built-in ×1

linux ×1

pipe ×1

shell ×1