I've been trying to compile some ocaml packages and keep running into some errors of the form sh: 1: Bad substitution (exit code 2), eg.
/bin/sh -exc echo | m4
/bin/sh: 1: Bad substitutionBut, /bin/sh -ec echo | m4 has no error. It seems that any command with both -e and -x flags passed to /bin/sh (/bin/sh: symbolic link to dash) results in this error. Is this the expected behaviour, because I can't see anything to that effect in the manual, and I can't remember ever having this happen before.
EDIT: actually I see the error with any /bin/sh -xc command, regardless of -e
Ubuntu 18.04
1 Answer
I finally found the problem. In my ~/.bashrc I set
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'Which the dash manual says gets output before every trace line when -x is set. Exporting PS4 without bashisms solves the problem.
I hadn't been expecting my ~/.bashrc to be read at all in this case, but since bash is being used to execute /bin/sh I assume those variables are being seen by dash as well, annoyingly.