我什么时候可以使用|&放大器;在Bash的?它是在其他shell使用吗? [英] When can I use |& in Bash? Is it usable in other shells?

查看:193
本文介绍了我什么时候可以使用|&放大器;在Bash的?它是在其他shell使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常看到这样的命令:

I often see commands like:

command1 |& command2

所以,我们在这里做的是标准错误重定向到标准输入,让他们都,成为标准输入到管道中的下一个元素。

So what we are doing here is to redirect stderr to stdin, so that both of them "become" stdin to the next element in the pipe.

或者更好的在猛砸参考手册 - >管道:

一个管道是之一分隔的简单命令序列
  控制经营者'|'或'|&放大器;

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

...

如果 |&安培; 时,命令1的标准错误,除了其
  标准输出,通过连接到命令command2的标准输入
  管;这是速记 2 - ;&放大器; 1 | 。的这种隐含重定向
  之后的任何执行标准错误到标准输出
  命令指定重定向。

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 | ?可它也是在其他任何外壳使用(KSH,CSH)?

However, I wonder: is this syntax usable in all Bash versions? That is, is it always interchangeable with 2>&1 |? Can it also be used in any other shell (ksh, csh...)?

推荐答案

此功能对于猛砸4+只:

This feature is for Bash 4+ only:

|& (bash4)

来源

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

来源

另外请注意的 checkbashisms 的脚本将其标记为好:

Also note that the checkbashisms script will flag it as well:

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

来源

这篇关于我什么时候可以使用|&放大器;在Bash的?它是在其他shell使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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