在 Linux bash 中,我看到使用|&以下運算子的腳本:
/opt/program.sh |& tee -a /var/log/program.log
|& 運算子的含義是什么?
問候
uj5u.com熱心網友回復:
根據Bash 參考手冊中的第 3.2.3 節“管道”,|&類似于|,除了:
如果
|&使用 ' ',則command1的標準錯誤除了其標準輸出外,還通過管道連接到command2的標準輸入;它是 的簡寫2>&1 |。標準錯誤到標準輸出的這種隱式重定向是在命令指定的任何重定向之后執行的。
也就是說——任何/opt/program.sh列印到標準輸出或標準錯誤的東西都將通過管道傳輸到tee -a /var/log/program.log.
uj5u.com熱心網友回復:
除了ruakh 的回答,這里有一些嘗試,作為In the shell 的完成,“2>&1”是什么意思?
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
但由于命令列順序很重要,這將被視為最后一次重定向:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/417466.html
標籤:
下一篇:如何使用fzf僅搜索目錄?
