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:
Syntax
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
#!/bin/bash
export GREETING="Hello from parent"
bash -c 'echo "Child sees: $GREETING"'
Login to try C/C++/Java/PHP code in the editor
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
- Expecting an exported variable to change the parent shell, when export only passes values to child processes.
- Exporting a variable and then changing it in a child, which does not change the parent's value.
- Forgetting to export a variable that a called script needs, so it is empty there.
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: