bash - `shopt -s lastpipe` 如何影响 bash 脚本行为?

标签 bash shell

我正在尝试制作 ffcast屏幕转换工具 bash 4.1 向后兼容。

并在此 ffcast.bash脚本,有一行

shopt -s extglob lastpipe

lastpipe 选项仅在 bash 4.3 之后可用,我该怎么做才能模拟其效果?

最佳答案

lastpipe (顺便说一下,在 bash 4.2 中引入)只能通过不使用管道来模拟。您需要在当前 shell 中显式运行管道的最后一个命令,并从进程替换中重定向其输入

# foo | bar | baz becomes ...
baz < <(foo | bar)

或命名管道(也符合 POSIX 标准)
# foo | bar | baz becomes ...
mkfifo baz_input
foo | bar > baz_input &
baz < baz_input

关于bash - `shopt -s lastpipe` 如何影响 bash 脚本行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36340599/

相关文章:

linux - 我可以使用具有退出状态的命令替换,而不是标准输出吗?

regex - fgrep 匹配文字 "*"

bash - 使用 aria2c 并行下载多个文件

linux - 如何在shell脚本中更改日期格式

c - 后台execvp : how to do it properly?

bash - VSCode : Why is (pipenv) not displayed on the terminal? 上的 Pipenv

bash - 从基于 alpine 的 docker 运行 bash 脚本

bash - 在 Bash 脚本中随机选择并打印三个字符串之一

linux - 计算大文件中的字符长度

Linux 一个带管道操作的长shell命令