Search code examples
node.jsmacosoh-my-zshiterm2dotenv

Environment variable gets quoted in iTerm / terminal from .env


I have a .env file like this:

SOME_SECRET="84158be5-a644-4cd9-9350-5ec24efc67e9"

Now I'm installing dotenv:

npm install -g dotenv-cli

When running dotenv -p SOME_SECRET in iTerm2, I get this output:

dotenv -p SOME_SECRET
"84158be5-a644-4cd9-9350-5ec24efc67e9"

When doing the same in VS Code terminal, I get this output:

dotenv -p SOME_SECRET
84158be5-a644-4cd9-9350-5ec24efc67e9

The VS Code output (without quotes) is the expected one.

Trying the same on another machine (macOS Big Sur as well), the iTerm output is the same as in VS Code.

Back on the first machine, when running macOS Terminal, it shows the same behavior as iTerm2 - so it seems related to the zsh settings I guess. On the other hand, when changing the Terminal to "external" in VS Code according to the screenshot, it still shows the expected output:

enter image description here

What might cause this behavior?


Solution

  • Solved it: my .zshrc did contain this entry:

    source ~/.dotenv.sh
    

    ~/dotenv.sh has this content:

    cd()
    {
        debug()
        {
            if [ $DOTENVSH_DEBUG = true ]; then
                echo $1
            fi
        }
    
        loadenv()
        {
            debug "Loading $1"
            for i in $(cat $1); do
                export $i
            done
        }
    
        builtin cd $@
        ERR=$?
    
        if [ $ERR -ne 0 ]; then; return $ERR; fi
    
        if [ -e .env ]; then
            loadenv .env
        fi
    }%