以下作品:
[nir page]$ echo 1 2>&1 >&1
1
但是當我使用變數時,它不會:
[nir page]$ out="&1"
[nir -page]$ echo $out
&1
[nir page]$ echo 1 2>$out >$out
[nir page]$
我究竟做錯了什么?
想法是將輸出發送到/dev/null除非我要求標準輸出。
uj5u.com熱心網友回復:
我究竟做錯了什么?
您假設部分語法可以存盤在變數中。他們不能。&必須在行上按字面輸入,不能在變數中。
想法是將輸出發送到 /dev/null ,除非我要求標準輸出。
您為此使用檔案描述符。
if when I dont ask; then
exec 1>/dev/null 2>&1
fi
echo 1
或者使用linux/dev/*檔案:
out=/dev/stdout # or /dev/null
echo 1 >"$out"
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439450.html
