2016-08-26 8 views
0

以下のコマンドがbashで何をするのか知りたいと思います。set -eとset -aはbashで何をするのですか?setコマンドで使用できる他のオプションは何ですか。

  • セット
  • セット-a -e

私はセットで使うとその意味行うことができ、他のオプションとは何か。 man pageから

+0

私は-eが非ゼロの状態での終了を意味しました。今、-aオプションの意味を知る必要があります。 – thinkingmonster

+3

'man set'を試しましたか? bashの組み込みコマンドを表示しているmanページに移動します。そこには、 'set'オプションのすべてを説明するセクションがあります。 –

+2

答えを見つけるために 'man bash'を実行してください。 – gzh

答えて

6

後続のコマンドの環境への輸出用に変更または作成されているマーク変数と関数-a

-e番出口すぐ(パイプラインを参照)パイプラインであれば、どの(シンプルコマンドを参照)、リスト(リストを参照)、 、または複合コマンド(複合コマンドを参照)から構成されていて、0以外の数値を返します。 失敗したコマンドが、 コマンドリストのすぐ後にある、またはuntilキーワードの一部である場合、シェルは終了しません。 で実行されたコマンドの一部またはifステートメントでテストの一部分 が実行されます。最後の& &または||のいずれかのコマンド、パイプライン内の最後のコマンド、または が反転されている場合を除き、すべてのコマンドがリストに含まれています。サブシェル以外の複合コマンド が、-eが無視されている間にコマンドが失敗したためにゼロ以外のステータスを返した場合、シェルは終了しません。 ERRのトラップが設定されている場合は、シェルが終了する前に が実行されます。

このオプションは、シェル環境に適用され、それぞれが個別に 環境をサブシェル(コマンドの実行環境を参照)、および 原因サブシェルは サブシェル内のすべてのコマンドを実行する前に終了することがあります。

化合コマンドまたはシェル関数は-e は無視されているコンテキスト内で実行される場合、化合物内 コマンドまたは関数本体を実行したコマンドのどれでも -e場合、-e設定の影響を受けませんが設定され、コマンドが失敗ステータスを返します。複合コマンドまたはシェル関数が、 -eが無視されるコンテキストで実行中に-eを設定すると、複合コマンドまたは関数呼び出しを含むコマンドが完了するまで、その設定は無効になります。

5

てみランニング:

help set 

出力は次のとおりです。

set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] 
    Set or unset values of shell options and positional parameters. 

    Change the value of shell attributes and positional parameters, or 
    display the names and values of shell variables. 

    Options: 
     -a Mark variables which are modified or created for export. 
     -b Notify of job termination immediately. 
     -e Exit immediately if a command exits with a non-zero status. 
     -f Disable file name generation (globbing). 
     -h Remember the location of commands as they are looked up. 
     -k All assignment arguments are placed in the environment for a 
      command, not just those that precede the command name. 
     -m Job control is enabled. 
     -n Read commands but do not execute them. 
     -o option-name 
      Set the variable corresponding to option-name: 
       allexport same as -a 
       braceexpand same as -B 
       emacs  use an emacs-style line editing interface 
       errexit  same as -e 
       errtrace  same as -E 
       functrace same as -T 
       hashall  same as -h 
       histexpand same as -H 
       history  enable command history 
       ignoreeof the shell will not exit upon reading EOF 
       interactive-comments 
          allow comments to appear in interactive commands 
       keyword  same as -k 
       monitor  same as -m 
       noclobber same as -C 
       noexec  same as -n 
       noglob  same as -f 
       nolog  currently accepted but ignored 
       notify  same as -b 
       nounset  same as -u 
       onecmd  same as -t 
       physical  same as -P 
       pipefail  the return value of a pipeline is the status of 
          the last command to exit with a non-zero status, 
          or zero if no command exited with a non-zero status 
       posix  change the behavior of bash where the default 
          operation differs from the Posix standard to 
          match the standard 
       privileged same as -p 
       verbose  same as -v 
       vi   use a vi-style line editing interface 
       xtrace  same as -x 
     -p Turned on whenever the real and effective user ids do not match. 
      Disables processing of the $ENV file and importing of shell 
      functions. Turning this option off causes the effective uid and 
      gid to be set to the real uid and gid. 
     -t Exit after reading and executing one command. 
     -u Treat unset variables as an error when substituting. 
     -v Print shell input lines as they are read. 
     -x Print commands and their arguments as they are executed. 
     -B the shell will perform brace expansion 
     -C If set, disallow existing regular files to be overwritten 
      by redirection of output. 
     -E If set, the ERR trap is inherited by shell functions. 
     -H Enable ! style history substitution. This flag is on 
      by default when the shell is interactive. 
     -P If set, do not resolve symbolic links when executing commands 
      such as cd which change the current directory. 
     -T If set, the DEBUG trap is inherited by shell functions. 
     -- Assign any remaining arguments to the positional parameters. 
      If there are no remaining arguments, the positional parameters 
      are unset. 
     - Assign any remaining arguments to the positional parameters. 
      The -x and -v options are turned off. 

    Using + rather than - causes these flags to be turned off. The 
    flags can also be used upon invocation of the shell. The current 
    set of flags may be found in $-. The remaining n ARGs are positional 
    parameters and are assigned, in order, to $1, $2, .. $n. If no 
    ARGs are given, all shell variables are printed. 

    Exit Status: 
    Returns success unless an invalid option is given. 
関連する問題