"+=" Bash syntax is misinterpreted in Xenial but works in Bionic

As part of a Travis build, I’m running a relatively simple bash script downloaded from here.

On xenial only, in the third job here, I get an error here as follows:

+++ADD_ARGS+=(--static --with-lapack='-llapack -lblas -lgfortran -lquadmath -lm')
+++export ADD_ARGS+
coinbrew/.ci/setup_environment.sh: line 37: export: `ADD_ARGS+': not a valid identifier

I can’t see what’s going on with this error and it only happens in this one particular case. I’ve tried many little tweaks and have tired to replicate running the same script with the same exact versions of bash and have failed to uncover anything. There’s obviously a difference in how the script is being invoked on the actual build machine and the way I’m invoking it in trying to replicate. There is some subtlety around subshells, yada, yada, but the fact that this works on MacOS and (mostly) works on xenial leads me to believe that the problem is not with anything in my setup, but who knows. I’ve been trying to track this down for some time, but I’m at my wit’s end.

I’d appreciate any ideas what to poke at next.

Ted

To follow up, I now ran the script in the same Docker container that seems to be used on the build machine (travisci/ci-ubuntu-1804:packer-1593521720-ca42795e) and everything works fine so there is something funny going on here…

Bash 4.3 (the one in Xenial) does not support += under export:

$ sudo docker run -it ubuntu:xenial
# bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
<...>
# declare -a ADD_ARGS
# export ADD_ARGS=()
# export ADD_ARGS+=( --static --with-lapack='-llapack -lblas -lgfortran -lquadmath -lm' )
bash: export: `ADD_ARGS+': not a valid identifier
# ADD_ARGS+=( --static --with-lapack='-llapack -lblas -lgfortran -lquadmath -lm' )
#

Most probably, this is the entry for the corresponding bugfix in 4.4:

j.  There are a number of bug fixes to coproc, mapfile, declare, unset,
    and assignment statements that prevent nameref variables from creating
    and unsetting variables with invalid names.

5 posts were split to a new topic: Exported variables are suddenly empty

Imprint