# Travis incorrectly double-quotes environment variables

**URL:** <https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** bug\
**Created:** [March 9, 2020, 3:22pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496 "2020-03-09T15:22:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![lballabio](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lballabio/32/3989_2.png) [@lballabio](https://travis-ci.community/u/lballabio)\
**Post date:** [March 9, 2020, 3:22pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/1 "2020-03-09T15:22:30Z")

</div>

See [https://travis-ci.org/lballabio/QuantLib/jobs/660190388](https://travis-ci.org/lballabio/QuantLib/jobs/660190388).

I have quoted environment variables in my yml, such as for instance

```
env:
  global:
    - DOCKER_OPTS="--rm -ti -v ${HOME}/.ccache:/root/.ccache -v ${TRAVIS_BUILD_DIR}:/build -w /build"

```

As of this afternoon, the build started putting another pair of quotes around that (see line 435 in the job above) resulting in

```
$ export DOCKER_OPTS=""--rm -ti -v ${HOME}/.ccache:/root/.ccache -v ${TRAVIS_BUILD_DIR}:/build -w /build""

```

where the original quotes and the additional ones cancel out and leave the tokens unquoted.

Thanks,  
Luigi

---

<div class="post-metadata">

**Author:** ![ZedThree](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/zedthree/32/4157_2.png) [@ZedThree](https://travis-ci.community/u/ZedThree)\
**Post date:** [March 9, 2020, 3:39pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/2 "2020-03-09T15:39:26Z")

</div>

I’m seeing single quotes getting doubled up too, which is breaking our builds in a script that does

```bash
for package in $@

```

You can see here that the quotes are being passed through rather than being interpreted by the shell: [https://travis-ci.org/boutproject/BOUT-dev/jobs/660107324#L858](https://travis-ci.org/boutproject/BOUT-dev/jobs/660107324#L858)

---

<div class="post-metadata">

**Author:** ![famousgarkin](https://avatars.discourse-cdn.com/v4/letter/f/74df32/32.png) [@famousgarkin](https://travis-ci.community/u/famousgarkin)\
**Post date:** [March 9, 2020, 3:44pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/3 "2020-03-09T15:44:00Z")

</div>

Another instance of this is the Travis environment variables that should be unset/empty are actually set to `''` now, as if set by `VAR="''"`, hence the

```auto
${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}

```

fails to evaluate to default all around the place.

---

<div class="post-metadata">

**Author:** ![ridenaio](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@ridenaio](https://travis-ci.community/u/ridenaio)\
**Post date:** [March 9, 2020, 3:44pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/4 "2020-03-09T15:44:21Z")

</div>

Same situation, this code fails now, when tag is empty `- if [["$TRAVIS_TAG" != ""]]; then npm --no-git-tag-version version ${TRAVIS_TAG:1}; fi`

---

<div class="post-metadata">

**Author:** ![daviddavis](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/daviddavis/32/1384_2.png) [@daviddavis](https://travis-ci.community/u/daviddavis)\
**Post date:** [March 9, 2020, 3:47pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/5 "2020-03-09T15:47:16Z")

</div>

We’re having this problem too. All our builds are broken.

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/ashmaroli/32/3993_2.png) [@ashmaroli](https://travis-ci.community/u/ashmaroli)\
**Post date:** [March 9, 2020, 4:07pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/6 "2020-03-09T16:07:19Z")

</div>

Just encountered this issue with our builds as well…

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [March 9, 2020, 4:31pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/7 "2020-03-09T16:31:08Z")

</div>

It is actually undocumented in [https://docs.travis-ci.com/user/environment-variables/#global-variables](https://docs.travis-ci.com/user/environment-variables/#global-variables) whether it’s legal to pre-quote values – thus neither behavior is tested for.

A workaround right now for those affected is to remove quotes.

The syntax doesn’t make it clear whether the value is expected to be treated as a Bash expression or as a raw value – so I’m not sure what the “intuitive” behavior would be.

---

<div class="post-metadata">

**Author:** ![effigies](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/effigies/32/3864_2.png) [@effigies](https://travis-ci.community/u/effigies)\
**Post date:** [March 9, 2020, 4:32pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/8 "2020-03-09T16:32:06Z")

</div>

FWIW, removing quotes does not restore the old behavior. Tried it in [https://github.com/nipy/nibabel/pull/895](https://github.com/nipy/nibabel/pull/895), and variables with spaces were not set correctly.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [March 9, 2020, 4:33pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/9 "2020-03-09T16:33:20Z")

</div>

I guess we shouldn’t touch the value if there are _any_ kind of outer quotes.

But then how to deal with the smarty-pants who would write smth like this?

```auto
- VAR=abc"$foo"'$bar'baz

```

---

<div class="post-metadata">

**Author:** ![effigies](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/effigies/32/3864_2.png) [@effigies](https://travis-ci.community/u/effigies)\
**Post date:** [March 9, 2020, 4:40pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/10 "2020-03-09T16:40:37Z")

</div>

I’m not sure you need to catch every corner case… People are motivated to find a way to get the strings they want into their variables. Unless you’re worried about some kind of code injection, I would be inclined to let things like that fail.

I’m not personally invested in the quote syntax (apart from the time I’ll have to spend if we move away from the old style), just as long as I can get spaces and interpolate previously-defined variables. I’d rather not have to escape spaces, but if that’s what’s required, so be it.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [March 9, 2020, 4:45pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/11 "2020-03-09T16:45:05Z")

</div>

Most likely an issue arising from

> <https://github.com/travis-ci/travis-build/pull/1865>

  
which was later reverted by  

> <https://github.com/travis-ci/travis-build/pull/1868>

  
If applicable, you can restart the affected build(s)/job(s).

---

<div class="post-metadata">

**Author:** ![lballabio](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/lballabio/32/3989_2.png) [@lballabio](https://travis-ci.community/u/lballabio)\
**Post date:** [March 9, 2020, 4:56pm UTC](https://travis-ci.community/t/travis-incorrectly-double-quotes-environment-variables/7496/12 "2020-03-09T16:56:26Z")

</div>

You’re right, it seems to be working correctly now.
