Machine Type: x86_64-redhat-linux-gnu
Bash Version: 5.0
Patch Level: 7
Release Status: release
Description:
Bash appears to move the closing '}'
from after a closing here-document delimiter
to the start of the here-doc body
(just after the opening here-document delimiter)
in a function definition contained within
another function definition.
This conflicts with later invocations of /bin/sh , like:
$ /bin/sh
sh: demo: line 22: syntax error: unexpected end of file
sh: error importing function definition for `demo'
Workaround:
assign the text within the here-doc to a variable.
Repeat-By:
#!/bin/bash
bash --version 2>&1 | head -1
demo () {
# problem
function sub () { cat<<'EOFsub'
sub
EOFsub
} # this brace is moved to just after <<'EOFsub'
# workaround
function var () { local var="$(cat<<'EOFvar'
var
EOFvar
)"
echo "$var"
};
cat<<EOF
demo
EOF
# invoke sub-functions
sub;
var
}
declare -f -x demo
# display function definitions with moved '}'
typeset -f -p demo
# invoke main function
demo
[Prev in Thread]
Current Thread
[Next in Thread]
closing '}' misplaced in here-document in function,
Denis McKeon<=