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

export

In this page:

  1. export

export

export marks a variable so it's passed down into any child processes the script starts, such as other scripts or programs it calls. Without export, a variable only exists within the current shell and is invisible to subprocesses. This is how scripts share configuration with programs they invoke.

Note: Use export VAR=value when a variable needs to be visible to a program your script calls, not just the script itself.

Example: export

bash
#!/bin/bash
export GREETING="Hello from parent"

bash -c 'echo "Child sees: $GREETING"'

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.