# Problem with setting shell environment variables that have eval in them

**URL:** <https://discuss.circleci.com/t/problem-with-setting-shell-environment-variables-that-have-eval-in-them/25880>\
**Category:** Build Environment\
**Tags:** envars, circle-yml\
**Created:** [October 21, 2018, 9:55pm UTC](https://discuss.circleci.com/t/problem-with-setting-shell-environment-variables-that-have-eval-in-them/25880 "2018-10-21T21:55:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-shprd](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@james-shprd](https://discuss.circleci.com/u/james-shprd)\
**Post date:** [October 21, 2018, 9:55pm UTC](https://discuss.circleci.com/t/problem-with-setting-shell-environment-variables-that-have-eval-in-them/25880/1 "2018-10-21T21:55:17Z")

</div>

Hi,

I’m trying to set an environment variable from the output of a command which finds the current nodejs project version, e.g.:

```
      - run:
      name: Get project version
      command: |
        if [$CIRCLE_BRANCH = 'master']; then
          echo export TAG=$(eval node -p "require('../package.json').version") >> $BASH_ENV
        else
          echo export TAG=$(eval node -p "require('../package.json').version")_$CIRCLE_BUILD_NUM >> $BASH_ENV
        fi

```

However this doesn’t get executed correctly and I get the following error in the console logs:

```
/bin/bash: eval: line 3: syntax error near unexpected token `('
/bin/bash: eval: line 3: `node -p require('../package.json').version'

```

I’ve tried combinations of adding and escaping more quotes but nothing seems to work. Any ideas?

Thanks

---

<div class="post-metadata">

**Author:** ![james-shprd](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@james-shprd](https://discuss.circleci.com/u/james-shprd)\
**Post date:** [October 23, 2018, 10:28am UTC](https://discuss.circleci.com/t/problem-with-setting-shell-environment-variables-that-have-eval-in-them/25880/2 "2018-10-23T10:28:45Z")

</div>

The solution is:

```
  - run:
      name: Get project version
      command: |
        if [$CIRCLE_BRANCH = 'master']; then
          echo export TAG=$(eval node -p "require\(\'./package.json\'\).version") >> $BASH_ENV
        else
          echo export TAG=$(eval node -p "require\(\'./package.json\'\).version")_$CIRCLE_BUILD_NUM >> $BASH_ENV
        fi
```

---

<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:** [November 2, 2018, 10:28am UTC](https://discuss.circleci.com/t/problem-with-setting-shell-environment-variables-that-have-eval-in-them/25880/3 "2018-11-02T10:28:47Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
