herokuzsh

Parse error near `&' while setting Heroku config vars


I am setting my Heroku config variable through terminal, and get this error:

zsh: parse error near `&'

my zsh version is 5.7.1 platform: Mac Mojave

Here is the command I'm running:

heroku config:set vidly_db=mongodb://vidlyuser:mypassword@vidly-shard-00-00-yyjmw.mongodb.net:27017,vidly-shard-00-01-yyjmw.mongodb.net:27017,vidly-shard-00-02-yyjmw.mongodb.net:27017/test?ssl=true&replicaSet=vidly-shard-0&authSource=admin&retryWrites=true

Solution

  • & is a special character in Zsh (and Bash, and most other Unixy shells)¹. Wrap your value in single quotes:

    heroku config:set vidly_db='mongodb://vidlyuser:mypassword@vidly-shard-00-00-yyjmw.mongodb.net:27017,vidly-shard-00-01-yyjmw.mongodb.net:27017,vidly-shard-00-02-yyjmw.mongodb.net:27017/test?ssl=true&replicaSet=vidly-shard-0&authSource=admin&retryWrites=true'
    

    ¹For example, it's used for backgrounding jobs.