# Travis creates a " folder if you try to use a variable as the cache

**URL:** <https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125>\
**Category:** Travis CI Discussions & Feedback\
**Created:** [July 8, 2019, 5:48pm UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125 "2019-07-08T17:48:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NotoriousPyro](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/notoriouspyro/32/2197_2.png) [@NotoriousPyro](https://travis-ci.community/u/NotoriousPyro)\
**Post date:** [July 8, 2019, 5:48pm UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125/1 "2019-07-08T17:48:58Z")

</div>

Create env variables such as this:

```
env:
    global:
      - TRAVIS_GOCACHE=$(go env | grep GOCACHE | cut -d "=" -f 2)

```

Now try to create a cache based on this variable in your matrix:

```
jobs:
  include:
    - &backend
      language: go
      go: 1.12.x
      cache:
        directories:
          - $TRAVIS_GOCACHE

```

Travis log:

```
fetching craig-develop/cache-linux-xenial-c3174378f6091b8027b72ca31a800d16e049aa069cf386d5041ac6c4212d9b15--go-1.12.x.tgz
found cache
0.00s1.15sadding /home/travis/gopath/src/github.com/flexera/beacon-monitoring/"/home/travis/.cache/go-build" to cache
creating directory /home/travis/gopath/src/github.com/flexera/beacon-monitoring/"/home/travis/.cache/go-build"

```

Log onto the machine:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/travis_ci/original/2X/e/e13d0097a82d3041445d79cd6d01a831d413323b.png)

Build fails:

```
The command "GOOS=$TRAVIS_GOOS GOARCH=$TRAVIS_GOARCH go get -v -t ./..." failed and exited with 1 during .
```

---

<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:** [July 8, 2019, 6:03pm UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125/2 "2019-07-08T18:03:09Z")

</div>

When reporting a problem, please include relevant build URLs. Thanks.

---

<div class="post-metadata">

**Author:** ![NotoriousPyro](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/notoriouspyro/32/2197_2.png) [@NotoriousPyro](https://travis-ci.community/u/NotoriousPyro)\
**Post date:** [July 8, 2019, 6:05pm UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125/3 "2019-07-08T18:05:05Z")

</div>

[https://travis-ci.com/flexera/beacon-monitoring/builds/118298417](https://travis-ci.com/flexera/beacon-monitoring/builds/118298417)

---

<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:** [July 8, 2019, 6:12pm UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125/4 "2019-07-08T18:12:28Z")

</div>

Note that the `TRAVIS_GOCACHE` is assigned a string containing `"`:

```auto
$ go env | grep GOCACHE | cut -d "=" -f 2
"/home/travis/.cache/go-build"

```

You can see this in the logs.

My guess is that our caching utilities don’t consider this possibility, and having problems because of it. You probably don’t want to cache this (almost certainly nonexistent) directory, either.

What you can try instead, is to `eval` what you want to set (since `go env` returns strings with `"` in them). For example:

```auto
eval export TRAVIS_$(go env | grep GOCACHE)

```

Notice that you should generally stay away from setting your own `$TRAVIS_*` environment variables. We may use them without notice and it can break your builds in unexpected ways.

---

<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:** [July 10, 2019, 2:55am UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125/5 "2019-07-10T02:55:49Z")

</div>

> [@NotoriousPyro](#):
>
> ```
> env:
> global:
> - TRAVIS_GOCACHE=$(go env | grep GOCACHE | cut -d "=" -f 2)
> 
> ```

Is it even legal to put shell commands into variable values? Is this documented somewhere?  
I expected anything you provide to be assigned to the variable verbatim.

---

<div class="post-metadata">

**Author:** ![NotoriousPyro](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/notoriouspyro/32/2197_2.png) [@NotoriousPyro](https://travis-ci.community/u/NotoriousPyro)\
**Post date:** [July 10, 2019, 7:59am UTC](https://travis-ci.community/t/travis-creates-a-folder-if-you-try-to-use-a-variable-as-the-cache/4125/6 "2019-07-10T07:59:53Z")

</div>

Well, it works - whether or not it’s _legal_ (in what sense you’re talking about legality I’m not certain) or wanted by the Travis team.

Ultimately, anything you put in there would be interpreted by the shell as it’s an environment variable.
