2017-10-16 5 views

答えて

2

独立したコマンドではありません。実際にはコマンドではありません。

これはコマンドラインの構文です。コマンドを実行する前にいくつかの変数を設定できます。変数はこのコマンドでのみ設定されます。

var1=val1 var2=val2... cmd 

単純なコマンドは、オプションの変数代入 が空白で区切られた単語とリダイレクションが続き、 制御オペレータによって終了の配列です。最初のワードは、実行されるコマンドを と指定し、引数0として渡されます。残りの単語は、呼び出されたコマンドに引数として渡される です。

2

man bashSIMPLE COMMAND EXPANSIONセクションでは、構文を説明しています

SIMPLE COMMAND EXPANSION 
     When a simple command is executed, the shell performs the following 
     expansions, assignments, and redirections, from left to right. 

     1.  The words that the parser has marked as variable assignments 
       (those preceding the command name) and redirections are saved 
       for later processing. 

     2.  The words that are not variable assignments or redirections are 
       expanded. If any words remain after expansion, the first word 
       is taken to be the name of the command and the remaining words 
       are the arguments. 

     3.  Redirections are performed as described above under REDIRECTION. 

     4.  The text after the = in each variable assignment undergoes tilde 
       expansion, parameter expansion, command substitution, arithmetic 
       expansion, and quote removal before being assigned to the vari- 
       able. 

     If no command name results, the variable assignments affect the current 
     shell environment. Otherwise, the variables are added to the environ- 
     ment of the executed command and do not affect the current shell envi- 
     ronment. If any of the assignments attempts to assign a value to a 
     readonly variable, an error occurs, and the command exits with a non- 
     zero status. 

     If no command name results, redirections are performed, but do not 
     affect the current shell environment. A redirection error causes the 
     command to exit with a non-zero status. 

     If there is a command name left after expansion, execution proceeds as 
     described below. Otherwise, the command exits. If one of the expan- 
     sions contained a command substitution, the exit status of the command 
     is the exit status of the last command substitution performed. If 
     there were no command substitutions, the command exits with a status of 
     zero. 

ポイント1は明らかに、コマンド名の前に複数の変数の割り当てを可能にします。

ポイントの後の段落では、コマンド名なしでの割り当てが可能です。

+0

また、次の便利な 'EXPANSIONコマンドラインで単語が分割された後に展開されます。'という意味で、変数展開の前にスペース区切りの任意の数の割り当てに単語分割が適用されます。 –

関連する問題