正如高级bash脚本指南中所描述的,exec可以用来重定向I/O,所以我只需在shell中编写一些案例。重定向stdout或stderr运行良好,但重定向stdin使shell注销。有什么解释吗?
命令:
exec < file发布于 2013-05-19 03:42:50
来自bash的BASH_BUILTINS手册页(man exec)
exec [-cl] [-a name] [command [arguments]]
If command is specified, it replaces the shell. No new process
is created. The arguments become the arguments to command. If
the -l option is supplied, the shell places a dash at the begin-
ning of the zeroth argument passed to command. This is what
login(1) does. The -c option causes command to be executed with
an empty environment. If -a is supplied, the shell passes name
as the zeroth argument to the executed command. If command can-
not be executed for some reason, a non-interactive shell exits,
unless the shell option execfail is enabled, in which case it
returns failure. An interactive shell returns failure if the
file cannot be executed. If command is not specified, any redi-
rections take effect in the current shell, and the return status
is 0. If there is a redirection error, the return status is 1.因此,如您所见,如果一个命令完成了->退出,如果一个命令失败了->退出.
将文件重定向到exec会失败.
除非它包含一行有效的代码,否则也不会退出,除非退出它。
(否则它会运行,然后退出.)
https://stackoverflow.com/questions/16631107
复制相似问题