Skip to content
Learn Netverks

Lesson

Step 25/36 69% through track

env-vars-bash

Environment variables

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Environment variables: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Environment variables in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Environment variables in contexts like: CI jobs, server maintenance, local dev automation, and Git hooks.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons.

When you can explain the previous lesson's ideas without copying starter code.

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.sh

Prefix assignments apply only to that command—useful for quick tests without polluting the shell.

Important interview questions and answers

  1. Q: export purpose?
    A: Puts variable into the environment inherited by child processes.
  2. Q: Why .env.example?
    A: Documents required keys without leaking real secrets.

Self-check

  1. What command filters environment lines matching APP_?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • export in CI?
  • .env vs shell?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump