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

export

export is like handing a copy of your note to the friends you invite over. Without it, the note stays in your pocket and the programs you start cannot see it.

In this page:

  1. export
Syntax
bash
export VARIABLE_NAME="value"

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"'
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Expecting an exported variable to change the parent shell, when export only passes values to child processes.
  2. Exporting a variable and then changing it in a child, which does not change the parent's value.
  3. Forgetting to export a variable that a called script needs, so it is empty there.

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.