"shopt -s lastpipe"如何影响bash脚本行为? [英] how does `shopt -s lastpipe` affect bash script behavior?

查看:128
本文介绍了"shopt -s lastpipe"如何影响bash脚本行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使 ffcast 屏幕投射工具bash 4.1向后兼容.

I am trying to make ffcast screen casting tool bash 4.1 backwards compatible.

,并在此 ffcast.bash 脚本中,有一条线

and in this ffcast.bash script, there is oneline

shopt -s extglob lastpipe

lastpipe选项仅在bash 4.3之后可用,我该如何模拟它的效果?

lastpipe option is only available after bash 4.3, what can I do to emulate its effect?

推荐答案

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

lastpipe (introduced in bash 4.2, by the way) can only be simulated by not using a pipe. You need to explicitly run the last command of the pipe line in the current shell, and redirect its input from either a process substitution

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

或命名管道(也符合POSIX)

or a named pipe (which is POSIX-compliant as well)

# foo | bar | baz becomes ...
mkfifo baz_input
foo | bar > baz_input &
baz < baz_input

这篇关于"shopt -s lastpipe"如何影响bash脚本行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆