in Linux bash I see script using |& operator like:
/opt/program.sh |& tee -a /var/log/program.log
What is the meaning of |& operator?
Regards
CodePudding user response:
Per §3.2.3 "Pipelines" in the Bash Reference Manual, |& is similar to |, except that:
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 for2>&1 |. This implicit redirection of the standard error to the standard output is performed after any redirections specified by the command.
That is — anything that /opt/program.sh prints to standard output or to standard error will be piped into tee -a /var/log/program.log.
CodePudding user response:
In addition to ruakh's answer, here are some tries, as completion of In the shell, what does " 2>&1 " mean?
ls -ld /t{mp,nt} | wc
ls: cannot access '/tnt': No such file or directory
1 9 49
ls -ld /t{mp,nt} 2>&1 | wc
2 18 101
ls -ld /t{mp,nt} |& wc
2 18 101
But as command line order is important, this will be treated as last redirection:
ls -ld /t{mp,nt} 2>&1 1>/dev/tty | wc
drwxrwxrwt 11 root root 4096 Jan 19 08:39 /tmp
1 9 52
ls -ld /t{mp,nt} 1>/dev/tty |& wc
0 0 0
ls: cannot access '/tnt': No such file or directory
drwxrwxrwt 11 root root 4096 Jan 19 08:39 /tmp
