# Environment variables don't seem to work well with spaces in 2.0

**URL:** <https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020>\
**Category:** Bug Reports\
**Tags:** envars\
**Created:** [December 23, 2017, 12:36am UTC](https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020 "2017-12-23T00:36:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheeseweasel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cheeseweasel/32/10173_2.png) [@cheeseweasel](https://discuss.circleci.com/u/cheeseweasel)\
**Post date:** [December 23, 2017, 12:36am UTC](https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020/1 "2017-12-23T00:36:18Z")

</div>

I have not tried with v1.0 config.

Anyway, the specific command I was running is

```
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD

```

This works well with no spaces in the password, but fails with spaces.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [December 23, 2017, 1:35pm UTC](https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020/2 "2017-12-23T13:35:49Z")

</div>

Have you tried quotes?

```
docker login -u '$DOCKER_USER' -p '$DOCKER_PASSWORD'

```

Remember that in shell commands, variables are just interpolated, so if you have `--switch my variable` then it will assign “my” to `--switch` and not know what to do with the second part. Quotes stop that happening.

It’s worth noting also that if you have quotes in your variables, they need to be escaped in order for the shell not to misinterpret them.

---

<div class="post-metadata">

**Author:** ![cheeseweasel](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/cheeseweasel/32/10173_2.png) [@cheeseweasel](https://discuss.circleci.com/u/cheeseweasel)\
**Post date:** [January 7, 2018, 11:55pm UTC](https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020/3 "2018-01-07T23:55:07Z")

</div>

Thanks @halfer, I did try that but it was then passing the string `'$DOCKER_USER'` for example to `docker login` rather than the environment variable. But once I figured out it was the spaces I just left it as that, maybe not ideal but it works. 😉

I just left it here because it felt like a bug - `docker login -u $DOCKER_USER -p $DOCKER_PASSWORD` will work in bash but not as a CircleCI run command. I think this could potentially cause others to lose time as the behaviour could be a bit random, and the error unlikely to directly point to the issue.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [January 8, 2018, 12:23am UTC](https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020/4 "2018-01-08T00:23:08Z")

</div>

> [@cheeseweasel](#):
>
> it was then passing the string ‘$DOCKER\_USER’

I can’t remember the specifics here, but maybe single and double quotes are treated differently in terms of whether variables interpolate? I know they are in PHP, and I forget if shells are different or the same! Try double quotes then, to see if that fixes it.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:35am UTC](https://discuss.circleci.com/t/environment-variables-dont-seem-to-work-well-with-spaces-in-2-0/19020/5 "2018-06-18T11:35:21Z")

</div>


