Environment variables configure processes: API URLs, feature flags, credentials paths. Export only what child processes need—never commit secrets to Git.
export and env
export APP_ENV=production
export PORT=8080
env | grep APP_
bash -c 'echo "child sees $APP_ENV"'Child shells inherit exported variables—see Python os.environ for the same idea.
.env files pattern
set -a # auto-export all assignments
source .env # if file exists: set -a; source .env; set +a
set +a
echo "DB_HOST=$DB_HOST"Keep .env out of Git—use .env.example with fake values; learn ignore rules in Git.
Inline for one command
APP_ENV=staging PORT=3000 ./start.shPrefix assignments apply only to that command—useful for quick tests without polluting the shell.
Important interview questions and answers
- Q: export purpose?
A: Puts variable into the environment inherited by child processes. - Q: Why .env.example?
A: Documents required keys without leaking real secrets.
Self-check
- What command filters environment lines matching APP_?
- What does set -a do during sourcing?
Tip: Commit .env.example, not .env—see Git ignore patterns.
Interview prep
- export?
Places variable in environment for child processes.
- .env in Git?
Never commit secrets—use .env.example templates.