Why does bash report syntax errors when my C News scripts use a redirection before a subshell command?

Why does bash report syntax errors when my C News scripts use a redirection before a subshell command?


The actual command in question is something like

< file ( command )

According to the grammar given in the POSIX.2 standard, this construct
is, in fact, a syntax error. Redirections may only precede `simple
commands'. A subshell construct such as the above is one of the shell's
`compound commands'. A redirection may only follow a compound command.

This affects the mechanical transformation of commands that use `cat'
to pipe a file into a command (a favorite Useless-Use-Of-Cat topic on
comp.unix.shell). While most commands of the form

cat file | command

can be converted to `< file command', shell control structures such as
loops and subshells require `command < file'.

The file CWRU/sh-redir-hack in the bash-2.05a distribution is an
(unofficial) patch to parse.y that will modify the grammar to
support this construct. It will not apply with `patch'; you must
modify parse.y by hand. Note that if you apply this, you must
recompile with -DREDIRECTION_HACK. This introduces a large
number of reduce/reduce conflicts into the shell grammar.



Home FAQ