加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

什么时候可以在Bash中使用|&?它可用于其他外壳吗?

发布时间:2020-12-15 23:00:43 所属栏目:安全 来源:网络整理
导读:我经常看到如下命令: command1 | command2 所以我们在这里做的是将stderr重定向到stdin,以便它们“成为”stdin到管道中的下一个元素. 或者在Bash Reference manual - Pipelines中更好地描述: A pipeline is a sequence of simple commands separated by on
我经常看到如下命令:

command1 |& command2

所以我们在这里做的是将stderr重定向到stdin,以便它们“成为”stdin到管道中的下一个元素.

或者在Bash Reference manual -> Pipelines中更好地描述:

A pipeline is a sequence of simple commands separated by one of the
control operators ‘|’ or ‘|&’.

If |& is used,command1’s standard error,in addition to its
standard output,is connected to command2’s standard input through the
pipe; it is shorthand for 2>&1 |. This implicit redirection of the
standard error to the standard output is performed after any
redirections specified by the command.

但是,我想知道:这个语法在所有Bash版本中都可用吗?也就是说,它总是可以与2>& 1 |?互换?它还可以用在任何其他shell(ksh,csh ……)中吗?

解决方法

此功能仅适用于Bash 4:

|& (bash4)

Source

dd. The parser now understands `|&' as a synonym for `2>&1 |',which redirects the standard
    error for a command through a pipe.

Source

另请注意,checkbashisms脚本也会标记它:

's|&;' =>                    q<pipelining is not POSIX>,

Source

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读