[Help-bash] Interesting consequence of Bash's grammar
From:
Ioan-Andrei Bârsan
Subject:
[Help-bash] Interesting consequence of Bash's grammar
Date:
Thu, 27 Aug 2015 16:09:38 +0000
Hello everyone,
I was reading through Bash's source code today and looking at its grammar
(in `parse.y') when I noticed something peculiar. The following rule caught
my eye:
function_body: shell_command
{ $$ = $1; }
shell_command can, among other things, be the `{ ... }` group command, but
it can also be an if statement, or a while loop (see line 760). This means
that the following statement is legal Bash:
bar () if true; then echo "I am a weird funciton."; fi
Is this a known/intentional feature? Wouldn't it make more sense to define
`function_body' based on `group_command' instead of `shell_command'?
Kind regards,
Andrei