Alex Alex - 1 year ago 66
Bash Question

Global environment variables in a shell script

How to set a global environment variable in a bash script?

If I do stuff like



export FOO=bar

...the vars seem to stay in the local context, whereas I'd like to keep using them after the script has finished executing.

mob mob
Answer Source

Run your script with .


This will run the script in the current shell environment.

export governs which variables will be available to new processes, so if you say

export BAR=2

then $BAR will be available in the environment of, but $FOO will not.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download