At a prompt, I can type:
$ e() { echo $1; }
and get a function which echoes its first argument. I do not understand why this works. Since $1 is undefined in the current environment, it seems that the above should be equivalent to:
$ e() { echo ; }
What is the relevant quoting/interpolation rule that allows this behavior? Note that this has nothing to do with $1 being special: if you use $FOO, you get a function that echoes the value of $FOO at the time the function is called rather than the value of $FOO when the function is defined.
Not sure how I missed this, since it’s pretty clear in section 2.9.5:
When the function is declared, none of the expansions in wordexp shall be performed on the text in compound-command or io-redirect; all expansions shall be performed as normal each time the function is called. Similarly, the optional io-redirect redirections and any variable assignments within compound-command shall be performed during the execution of the function itself, not the function definition. See Consequences of Shell Errors for the consequences of failures of these operations on interactive and non-interactive shells.