[英]Why does "bash 2>out.txt" hide bash output?
我目前正在使用 zsh,並且正在嘗試從 zsh 啟動bash
以便在此bash
中運行的所有命令都將其 stderr 重定向到out.txt
。
bash 2>out.txt
確實完成了這項工作,但正常的 bash output ( stdout
?)消失了。
我的期望:
zsh> bash 2>out.txt
user@pc:~$ pwd
/home/user
我得到了什么:
pwd
/home/user
user@pc:~$
東西已經消失了。
為什么會這樣? 我認為user@pc:~$
應該打印到stdout
,但我嘗試將stdout
重定向到/dev/null
並且它仍然顯示。 它也沒有顯示在out.txt
中,這意味着它沒有打印到stderr
? 那為什么2>out.txt
讓它消失呢?
Bash 僅在交互模式下打印提示; 將其標准錯誤重定向到非終端使其脫離該模式。 您可以使用-i
強制交互模式,如果這樣做,您會注意到提示實際上打印到 stderr,而不是 stdout。
But in general, if you want to capture an interactive session, you should use the script
program (eg script -c bash out.txt
on Linux, script out.txt bash
on BSD/macOS).
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.