linux view environment variables
printenv
linux source env file
# The problem with source is that it requires the file to have a proper bash syntax, and some special characters will ruin it: =, ", ', <, >, and others. So in some cases you can just
source development.env
# But This version, however, withstands every special character in values:
set -a
source <(cat development.env |
sed -e '/^#/d;/^s*$/d' -e "s/'/'\''/g" -e "s/=(.*)/='1'/g")
set +a
# Explanation:
# -a means that every bash variable would become an environment variable
# /^#/d removes comments (strings that start with #)
# /^s*$/d removes empty strings, including whitespace
# "s/'/'\''/g" replaces every single quote with ''', which is a trick sequence in bash to produce a quote :)
# "s/=(.*)/='1'/g" converts every a=b into a='b'
# As a result, you are able to use special characters :)
To debug this code, replace source with cat and you'll see what this command produces.
linux source env file
# export.sh .env
set -a # export all variables created next
source $1
set +a # stop exporting
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us