簡體   English   中英

為什么“bash 2>out.txt”會隱藏 bash output?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM