这个不能输出ngn,而只是一个空行.
翻bash的手册找到这么一段:
3.7.1
When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right.
- The words that the parser has marked as variable assignments (those preceding the command name) and redirections are saved for later processing.
- The words that are not variable assignments or redirections are expanded (see Shell Expansions). 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.
- Redirections are performed as described above (see Redirections).
- 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 variable.
原来echo的参数 $name 在 name=ngn 这个赋值之前就已经被扩展了.这时自然是空了.所以不会输出内容.
验证:
~$ name=ngn perl -e 'print $ENV{name}'
ngn
~$
没有评论:
发表评论