Skip to content
Guest
Learn Linux · Course Syllabus Show lessons
Shell Basics · 7 min read · Beginner

Environment Variables, export & PATH

Configure CLI tools cleanly with export, PATH lookup order, and safe default parameter expansion (${VAR:-default}).

What you'll learn

  • Understand the difference between local shell variables and exported environment variables
  • Inspect executable resolution order with which and echo $PATH
  • Provide safe fallback values in Bash using ${VAR:-default}

When you type python3 or node, Linux searches each colon-separated directory in $PATH from left to right and runs the first matching executable. In Bash scripts, ${PORT:-8787} lets you read an environment variable with a clean fallback if it is unset or empty.

Fill-in-the-Blank Exercise

Export & Default Expansion

Export APP_ENV to child processes and fall back to 'prod' if unset.

 APP_ENV="staging"
echo "${APP_ENVprod}"

Live Bash Lab

Bashenv_vars.sh
Expected OutputClick “Run Live” to compile with GNU Bash
Starting in production on port 8787

Check Your Understanding

Score: 0 / 1

1. What does ${PORT:-3000} evaluate to in Bash when PORT is unset?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind