Op 03-07-17 om 15:18 schreef Joerg Schilling:
> In our case, it is doubtful whether something like:
> 
>       var=value
> 
> allows IO redirection at all, as there is no command. Note that we recently
> discovered that var=$(cmd) does not set $? because there is no regular 
> command.
> 
>       { var=value; }
> 
> converts the pure assignement into something tha can be seen as a construct 
> that
> forms a command and thus allows redirection.

That makes sense, thanks. I think I found the exact answer in 2.9.1
"Simple Commands"[*]:

[...]
| 3. Redirections shall be performed as described in Redirection.
|
| 4. Each variable assignment shall be expanded for tilde expansion,
|    parameter expansion, command substitution, arithmetic expansion,
|    and quote removal prior to assigning the value.
|
| In the preceding list, the order of steps 3 and 4 may be reversed if
| no command name results from step 2 or if the command name matches
| the name of a special built-in utility; see Special Built-In
| Utilities.

There is no command name, so apparently bash, ksh93 and FreeBSD sh
reverse the order of steps 3 and 4, as allowed by the last paragraph
quoted above. Using the braces forces them to evaluate the redirections
in the order I want, as per 2.9.4 Compound Commands.

- M.

[*]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01

Reply via email to