Skip to content

Instantly share code, notes, and snippets.

@devzom
Created Mar 16, 2022
Embed
What would you like to do?
bash: Read .env file variable in Bash
# this will skip search for lines with variable starting with # (hashtag) ex: # VAR1 as its commented out
# Ex: we have .env file with variables:
# #VAR1=123
# VAR2=xyz
# NPM_TOKEN=12312323fdf21313
export "$(grep -vE "^(#.*|\s*)$" .env)"
# didn't respond VAR1 as it contain #, so it's commented out.
# responds with single value ex NPM_TOKEN:
echo $NPM_TOKEN # just print the single variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment