Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15072

closing '}' misplaced in here-document in function

From Denis McKeon <dmckeon@swcp.com>
Newsgroups gnu.bash.bug
Subject closing '}' misplaced in here-document in function
Date 2019-06-29 10:44 -0700
Message-ID <mailman.1601.1561830548.10840.bug-bash@gnu.org> (permalink)
References <974cfa51-f126-b373-f471-374a4b695e4a@swcp.com>

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

closing '}' misplaced in here-document in function Denis McKeon <dmckeon@swcp.com> - 2019-06-29 10:44 -0700

csiph-web