Not relevant to your example, but you can also get the Bad substitution
error in Bash for any substitution syntax that Bash does not recognize. This could be:
bash -c '${x }'
bash -c '${x;-}'
bash -c '${x@Q}'
before Bash 4.4.If you have multiple substitutions in the same expression, Bash may not be very helpful in pinpointing the problematic expression. E.g.:
$ bash -c '"${x } multiline string
$y"'
bash: line 1: ${x } multiline string
$y: bad substitution