← Back to Bash Course | Chapter 2: Variables & Types | Lesson 5 of 13

Environment Variables

In this page:

  1. Environment Variables

Environment Variables

Environment variables like $HOME, $USER, and $PATH are set by the system or shell and are available to every script and program that runs. They carry configuration and context, such as the current user's home directory. You can read them just like any other variable, with $.

Note: Run env or printenv in a terminal to see all environment variables currently set.

Example: Environment Variables

bash
#!/bin/bash
echo "Home directory: $HOME"
echo "Current user: $USER"
echo "Shell: $SHELL"

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.