Bug 1727952

Summary: Parsing commands break when using $$ in command substitution $(..)
Product: Red Hat Enterprise Linux 8 Reporter: Paul Dwyer <pdwyer>
Component: bashAssignee: Siteshwar Vashisht <svashisht>
Status: CLOSED ERRATA QA Contact: Karel Volný <kvolny>
Severity: high Docs Contact:
Priority: urgent    
Version: 8.1CC: fkrska, jonathandavies, jwboyer, kdudka, kvolny, rcadova, stevekay, svashisht
Target Milestone: rcKeywords: Patch, Reproducer, ZStream
Target Release: 8.0Flags: pdwyer: needinfo-
fkrska: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: bash-4.4.19-10.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1729750 (view as bug list) Environment:
Last Closed: 2019-11-05 22:25:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1729750    

Description Paul Dwyer 2019-07-08 16:04:13 UTC
Description of problem:
When using $$ in command substitutionusing $(...) the command is not parsed correctly, the same command works fine in bash on earlier versions of RHEL (e.g. 4, 5, 6, 7)

Version-Release number of selected component (if applicable):
bash-4.4.19-7.el8.x86_64

How reproducible:
always

Steps to Reproduce:
1. run A=$(awk -v p=$$ '{print $0}' <testfile)
2. returns awk error ass command is not parsed correctly
3.

Actual results:
# A=$(awk -v p=$$ '{print $0}' <testfile)
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:		GNU long options: (standard)
	-f progfile		--file=progfile
	-F fs			--field-separator=fs
	-v var=val		--assign=var=val
Short options:		GNU long options: (extensions)
	-b			--characters-as-bytes
	-c			--traditional
	-C			--copyright
	-d[file]		--dump-variables[=file]
	-D[file]		--debug[=file]
	-e 'program-text'	--source='program-text'
	-E file			--exec=file
	-g			--gen-pot
	-h			--help
	-i includefile		--include=includefile
	-l library		--load=library
	-L[fatal|invalid]	--lint[=fatal|invalid]
	-M			--bignum
	-N			--use-lc-numeric
	-n			--non-decimal-data
	-o[file]		--pretty-print[=file]
	-O			--optimize
	-p[file]		--profile[=file]
	-P			--posix
	-r			--re-interval
	-s			--no-optimize
	-S			--sandbox
	-t			--lint-old
	-V			--version

To report bugs, see node `Bugs' in `gawk.info'
which is section `Reporting Problems and Bugs' in the
printed version.  This same information may be found at
https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
PLEASE do NOT try to report bugs by posting in comp.lang.awk.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
	gawk '{ sum += $1 }; END { print sum }' file
	gawk -F: '{ print $1 }' /etc/passwd

# echo $?
1

cat $A


Expected results:
# A=$(awk -v p=$$ '{print $0}' <testfile)

# echo $?
0


Additional info:
running this under bash -x see there is no space after the substition of the pid from $$

# A=$(awk -v p=$$ '{print $0}' <testfile)
++ awk -v 'p=3749{print $0}'    <-- no space between pid and "{"
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...

Command runs successfully if you add an extra space e.g.
# A=$(awk -v p=$$  '{print $0}' <testfile)
++ awk -v p=3749 '{print $0}'
+ A='Some multi line
text
test
more text'
...


This only appears to be when running a command substitution with $()
works fine when using backticks e.g.

# A=`awk -v p=$$ '{print $0}' <testfile`
++ awk -v p=3749 '{print $0}'
+ A='Some multi line
text
test
more text'
...

Comment 5 Siteshwar Vashisht 2019-07-10 13:14:22 UTC
Upstream discussion https://lists.gnu.org/archive/html/bug-bash/2017-01/msg00065.html

Comment 22 errata-xmlrpc 2019-11-05 22:25:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2019:3594