0
The POSIX shell grammar at http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02
says
pipe_sequence : command
| pipe_sequence '|' linebreak command
;
command : simple_command
| compound_command
| compound_command redirect_list
| function_definition
which means, function definition can be a term in a pipe sequence. How is this possible? The function definition cannot have standard input or output and it is not a command that can be executed. Only a function call, which is a simple command, can be executed.
Added after the first comment and answer:
If we split off function_definition
from command
here, and add it as another alternative wherever else command
appears, then yes we are complicating the grammar a little.
But the payoff is much more important: the implementation of such shell, is much easier.
Because if you allow function definitions in a pipe, you have to deal with questions such as what is the scope of the function, and in what environment does it run. I don't believe such questions are in fact answered in the standard at all.
What is worse: a little more complexity in the grammar, or much more work and complexity for the implementer. If the former, then is this not a case of "tail wagging the dog"?
1It seems to work in bash, albeit it does nothing:
ls | f () { sed 's/^/=/;s/$/=/'; }
. – choroba – 2016-06-29T15:50:02.033