Menu
Coddy logo textTech

Export A Variable

Part of the Fundamentals section of Coddy's Terminal journey — lesson 63 of 82.

When you set a variable like MY_NAME="Alice", it exists only in your current shell. If you run a script or start another program, that variable won't be available to it. This is where export comes in.

The export command makes a variable available to any child processes, meaning programs or scripts launched from your current shell can access it:

export MY_NAME="Alice"

You can also export an existing variable:

MY_NAME="Alice"
export MY_NAME

Both approaches achieve the same result. The variable becomes part of the environment that gets passed to any command you run afterward.

To see the difference, consider running a script that tries to use $MY_NAME.

Without export, the script sees nothing. With export, the script can access the value.

This is why system variables like PATH and HOME are exported by default. They need to be available to every program you run.

You can verify a variable is exported by checking if it appears in the env output:

env | grep MY_NAME

Exported variables still disappear when you close the terminal. The next lesson covers how to make variables persist across sessions.

challenge icon

Challenge

Easy

Export a variable called PROJECT with the value terminal-course, then verify it was exported by filtering the env output to show only your new variable.

You can do this in a single line using export to set and export the variable at once, then pipe env through grep to find it.

Your output should be:

PROJECT=terminal-course

Hint: First run export PROJECT="terminal-course", then use env | grep PROJECT to verify it appears in the environment.

Cheat sheet

The export command makes a variable available to child processes (programs or scripts launched from your current shell):

export MY_NAME="Alice"

You can also export an existing variable:

MY_NAME="Alice"
export MY_NAME

Without export, variables exist only in the current shell and are not accessible to scripts or programs you run.

To verify a variable is exported, check if it appears in the env output:

env | grep MY_NAME

Exported variables disappear when you close the terminal.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals