首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >exec重定向stdin后的Shell注销

exec重定向stdin后的Shell注销
EN

Stack Overflow用户
提问于 2013-05-19 03:16:36
回答 1查看 839关注 0票数 1

正如高级bash脚本指南中所描述的,exec可以用来重定向I/O,所以我只需在shell中编写一些案例。重定向stdout或stderr运行良好,但重定向stdin使shell注销。有什么解释吗?

命令:

代码语言:javascript
复制
exec < file
EN

回答 1

Stack Overflow用户

发布于 2013-05-19 03:42:50

来自bash的BASH_BUILTINS手册页(man exec)

代码语言:javascript
复制
   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会失败.

除非它包含一行有效的代码,否则也不会退出,除非退出它。

(否则它会运行,然后退出.)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16631107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档