Why won't these braces work in a variable?
I have bash script with rsync with a --exclude option that calls a variable named EXCLUDE. That variable include literal curly braces.
#!/bin/bash
set -eB
EXCLUDE="{'.env','.git*','*.log','config/ssh','/dev','node_modules','/web/app/uploads'}"
rsync -av --dry-run --exclude=$EXCLUDE web/ ${DEPLOY_USER}@${DEPLOY_HOSTNAME}:/sites/${DEPLOY_DOMAIN}/files/web
If I echo $EXCLUDE I get the correct string:
echo $EXCLUDE
{'.env','.git*','*.log','config/ssh','/dev','node_modules','/web/app/uploads'}
If I run the script without the EXCLUDE variable I get the expected results:
rsync -av --dry-run --exclude={'.env','.git*','*.log','config/ssh','/dev','node_modules','/web/app/uploads'} web/ [email protected]:/sites/xyz.org/files/web
building file list ... done
./
test.txt
However if I run the command with the EXCLUDE variable present the results are not correct:
rsync -av --dry-run --exclude=${EXCLUDE} web/ ${DEPLOY_USER}@${DEPLOY_HOSTNAME}:/sites/${DEPLOY_DOMAIN}/files/web
building file list ... done
./
node_modules
test.log
test.txt
Note that if I use echo !!
to echo the last command that was run, the results are literally identical to the version without the $EXCLUDE variable:
echo !!
echo rsync -av --dry-run --exclude=$EXCLUDE web/ ${DEPLOY_USER}@${DEPLOY_HOSTNAME}:/sites/${DEPLOY_DOMAIN}/files/web
rsync -av --dry-run --exclude={'.env','.git*','*.log','config/ssh','/dev','node_modules','/web/app/uploads'} web/ [email protected]:/sites/xyz.org/files/web
I can even take the command that was returned by echo !!
, run it, and get the expected results!
I've tried enclosing $EXCLUDE in curly braces, I've tried escaping the braces in the variable, I've tried set -B
and with and without -e
. Even though bash seems to be sending literally curly braces to rsync rsync is not evaluating the contents to the braces.
Why won't these braces work in a variable?