[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
closing '}' misplaced in here-document in function
From: |
Denis McKeon |
Subject: |
closing '}' misplaced in here-document in function |
Date: |
Sat, 29 Jun 2019 10:44:25 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions
-fstack-protector-strong -grecord-gcc-switches
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic
-fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
-Wno-parentheses -Wno-format-security
uname output: Linux dt1 5.1.12-300.fc30.x86_64 #1 SMP Wed Jun 19
15:19:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
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 <=