Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do you need to include export for environment variables in bash profile / zshrc

Do you need to include export for environment variables in bash profile / zshrc?

I’m using Z shell (Zsh) for my terminal and in my .zshrc file I have the two lines:

varOne="foo"

export varTwo="bar"

When I echo either variable (ex: echo $varOne) within the terminal, the correct value is output. So is there a difference when prefixing the environment variable declaration with export inside the .zshrc file?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So is there a difference when prefixing the environment variable declaration with export inside the .zshrc file?

Yes, one is an environment variable and the other isn’t.

The difference doesn’t matter (much) to your shell, but to processes started by your shell. Environment variables are inherited by child processes, regular shell variables are not.

~ % foo=3; printenv foo
~ % export foo=3; printenv foo
3

In the first case, printenv has no variable named foo in its environment; in the second case, it does.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading