重定向Bash中的标准输入意味着Bash退出 [英] Redirecting standard input in Bash implies that Bash exits
问题描述
当我这样做的时候,
$ exec 6<&0 0</tmp/lines.txt
bash退出.为什么?
bash exits. Why?
谢谢
Eric J.
推荐答案
这使bash从/tmp/lines.txt
读取命令,从而在过程中重定向其输入.在文件中所有这些命令之后将不再有任何输入要处理,因此外壳程序将在执行完之后退出,就像执行外壳程序脚本一样.
That makes bash read commands from /tmp/lines.txt
redirecting its input in the process. There would no longer be any input to process after all those commands in the file so the shell just exits after it, just like executing a shell script.
如果您不希望在处理/tmp/lines.txt中的命令后退出bash,请确保可以像以下那样放回其输入:
If you want to not let bash exit after the commands in /tmp/lines.txt were processed, make sure that you could put back its input like:
exec 6<&0 < <(cat /tmp/lines.txt; echo; echo "exec <&6";)
既发送/tmp/lines.txt
的输入作为命令,又发送 exec<& 6
的输入,这些输入将回退& 6的输入
由进程替换封装.
Which send both inputs of /tmp/lines.txt
as commands and also exec <&6
that would put back input from &6
encapsulated by process substition.
更清洁的方法:
exec 6<&0 < <(cat /tmp/lines.txt; echo; echo "exec <&- <&6 6<&-";)
或者简单地:
exec 6<&0 < <(cat /tmp/lines.txt; echo; echo "exec <&6-)
这篇关于重定向Bash中的标准输入意味着Bash退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!