If you have a CHLD trap set, and you run any command that has more than
one command substitution, or an array subscript with more than one
command substituion in an arithmetic context, or also in a prompt
string, you will get parse errors.

  $ ./bash -c 'trap : CHLD; let "x[\$(exit 20)0]"'

  $ ./bash -c 'trap : CHLD; let "x[\$(exit 20)\$(exit 30)0]"'
  ./bash: trap: line 2: unexpected EOF while looking for matching `)'
  ./bash: command substitution: line 2: syntax error near unexpected token `)'
  ./bash: command substitution: line 2: `exit 30)0'

  $ ./bash -c 'trap ":" CHLD; foo=$(exit 20)$'

  $ ./bash -c 'trap ":" CHLD; foo=$(exit 20)$(exit 30)'
  ./bash: trap: line 2: unexpected EOF while looking for matching `)'
  ./bash: command substitution: line 2: syntax error near unexpected token `)'
  ./bash: command substitution: line 2: `exit 30)'

  $ ./bash -c 'trap ":" CHLD; : "$(exit 20)"; : "$(exit 30)"'

  $ ./bash -c 'trap ":" CHLD; : "$(exit 20)" "$(exit 30)"'
  ./bash: trap: line 2: unexpected EOF while looking for matching `)'
  ./bash: command substitution: line 2: syntax error near unexpected token `)'
  ./bash: command substitution: line 2: `exit 30)"'

  $ ./bash -c 'trap ":" CHLD; x="\$(exit 20)"; : "${x@P}"'

  $ ./bash -c 'trap ":" CHLD; x="\$(exit 20)\$(exit 30)"; : "${x@P}"'
  ./bash: trap: line 2: unexpected EOF while looking for matching `)'
  ./bash: command substitution: line 2: syntax error near unexpected token `)'
  ./bash: command substitution: line 2: `exit 30)'

I can reproduce this bug in bash 5.2, and on the devel branch.

o/
 emanuele6

Reply via email to