declare -f does not produce a function that is syntactically correct if it has a particular usage of heredoc and &&.
Example:
a() {
echo hi &&
cat >/dev/null <<-EOF &&
texttexttext
EOF
echo bye
}
with declare -f the definition will become
a ()
{
echo hi && cat > /dev/null <<-EOF
texttexttext
EOF
&& echo bye
}
which will trigger a syntax error if parsed as shell script (notice the change of position of &&).
It seems that the first command and the third command are necessary for this behavior.
declare -fdoes not produce a function that is syntactically correct if it has a particular usage of heredoc and&&.Example:
with
declare -fthe definition will becomewhich will trigger a syntax error if parsed as shell script (notice the change of position of
&&).It seems that the first command and the third command are necessary for this behavior.