On 07/14/2012 12:25 PM, Stefano Lattarini wrote:

>>
>> <file command
>>
>> is portable, but
>>
>> <file { compound command; }
>>
>> is not.  That is, only simple commands allow you to position a
>> redirection before the rest of the command.  'while' is a compound
>> command, so the redirection must come last.
>>
> Quick and helpful as usual :-)  Thanks Eric.
> 
> One question though: is "<file { compound command; }" also non-portable
> if we limit ourselves to POSIX shells?

From the POSIX grammar,
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02

command          : simple_command
                 | compound_command
                 | compound_command redirect_list
                 | function_definition


simple_command   : cmd_prefix cmd_word cmd_suffix
                 | cmd_prefix cmd_word
                 | cmd_prefix
                 | cmd_name cmd_suffix
                 | cmd_name

cmd_prefix       :            io_redirect
                 | cmd_prefix io_redirect
                 |            ASSIGNMENT_WORD
                 | cmd_prefix ASSIGNMENT_WORD

That is, it's hard-coded into the POSIX shell grammar that a
simple_command can start with redirections in the cmd_prefix, but a
compound_command can ONLY have redirections after the end of the
compound command, if you are being portable to POSIX.

-- 
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to