1

高度な bash スクリプト ガイドで説明されているように、exec を使用して I/O をリダイレクトできます。だから私は自分のシェルでいくつかのケースを書くだけです。stdout または stderr のリダイレクトはうまく機能しますが、stdin をリダイレクトするとシェルがログアウトされます。説明はありますか?

コマンド:

exec < file
4

2 に答える 2

3

シェルは、標準入力で EOF に達すると終了します (これがControl-D、ログアウトを入力する理由です)。からの読み取りが終了するfileと、それ以上入力がないため終了します。

于 2013-05-19T03:42:58.867 に答える
0

bash の BASH_BUILTINS man ページから ( 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 にリダイレクトすると失敗します...有効なコードである行が含まれて
ない限り'終了するまで終了しません。 (それ以外の場合は実行され、終了します...)

于 2013-05-19T03:42:50.710 に答える