Created
March 16, 2022 14:55
-
-
Save devzom/052f9806f3dd61d62fa71d1f28c85ae7 to your computer and use it in GitHub Desktop.
bash: Read .env file variable in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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