My directory structure is something like below.
.
|- test-master-65875866-backup
|- test-master-86565875
I tried the following code (also with double brackets)
if [ -d ${TRAVIS_REPO_SLUG#*/}-${TRAVIS_BRANCH}-*-backup ];
then
echo "Removing previous backup"
docker rm -f -v \$(docker ps -a -q --filter name=backup)
sudo rm -rf ${TRAVIS_REPO_SLUG#*/}-${TRAVIS_BRANCH}-*-backup
fi
but I'm still getting the error:
[: binary operator expected
I am wondering this error getting only in travis but not in local.
Note: ${TRAVIS_REPO_SLUG#*/}
contains test
and ${TRAVIS_BRANCH}
contains master
here.
I tried all of the following permutations but the error won't go away.
if [ -d "$TRAVIS_REPO_SLUG#*/"-"$TRAVIS_BRANCH"-*-backup ]; then
if [ -d "${TRAVIS_REPO_SLUG#*/}"-"${TRAVIS_BRANCH}"-*-backup ]; then
if [ -d "${TRAVIS_REPO_SLUG#*/}-${TRAVIS_BRANCH}-*-backup" ]; then
However the below code (with !) doesn't provide any error.
if [ ! -d ${TRAVIS_REPO_SLUG#*/}-${TRAVIS_BRANCH}-*-backup ]
printf %s $a
you should useprintf %s "$a"
. – Chris Davies Oct 09 '18 at 10:47"${TRAVIS_REPO_SLUG#*/}"-"${TRAVIS_BRANCH}"-*-backup
are of type directory? Or that there is at least one that is of type directory? In any case[ -d file ]
can take only one file, so you'll probably need a loop or a shell with glob qualifiers – Stéphane Chazelas Oct 09 '18 at 11:14bash -x
to see what happens – Stéphane Chazelas Oct 09 '18 at 11:18set -x
before andset +x
after the offending code and then [edit] your question and provide the output of your script... – Fabby Oct 09 '18 at 11:21<< EOF
instead of<< 'EOF'
so the variables are expanded by the local shell inside the here-doc. – Stéphane Chazelas Oct 09 '18 at 11:26