Bash parsing commands break when using $$ in command substitution $(...)

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 8
  • bash-4.4.19-7.el8

Issue

When using $$ in a command substitution $(...), bash cannot parse the command and it fails.

Bash ignores the space after $$and reports syntax error.

Same command works fine in earlier versions of bash on earlier RHEL versions.

Resolution

Update to bash-4.4.19-8.el8_0 shipped with Advisory RHBA-2019:2707 or newer.

Root Cause

Previously, having $$ inside command substitution was reported as syntax error . As a consequence, many scripts were broken. A patch has been applied to fix parsing $$ inside command substitution. As a result, $$ now working correctly inside command substitution.

Diagnostic Steps

The following command is used as an example

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

Returns an error from awk as it is run without a space between p=$$ and '{print}'

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments