more on bash env vars
Say you had a application that depended on certain environmental variables to be available before it ran.
To export all the variables to the environement in one shot, you can group them in a script file and then source
that file. For example:
touch set_env_vars.sh
(no chmod
needed for this example since we won’t be executing the script)
in env_vars.sh
:
#!/bin/bash
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_DB=my_cool_db
back at the terminal
source env_vars.sh
# alternative syntax:
# . env_vars.sh
env | grep -i postgres
you should see a list of those variables, now availabe to subprocesses of the current shell.