Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH: Is "export" needed, when setting a variable in .bashrc?

I wonder if there is a need to use "export" when setting a variable in .bashrc.

In my tests editing .bashrc there was no difference between

foo=bar

and

export foo=bar

In both cases, after login "echo $foo" outputs "bar".

I am using Debian Squeeze, if that matters.

Thank you guys in advance.

like image 959
casper Avatar asked Jun 09 '11 18:06

casper


2 Answers

Try creating a shell script that accesses the foo variable.

If foo was export'ed, it will be visible in the shell script, otherwise it won't.

like image 126
Blagovest Buyukliev Avatar answered Nov 02 '22 18:11

Blagovest Buyukliev


SuperUser has this covered.

Short answer: export makes sure the environment variable is set in child processes. If you don't export, it's only available in the same process/interactive session.

like image 44
Hank Gay Avatar answered Nov 02 '22 18:11

Hank Gay