I know that, Shell variables are not available to the parent or child shells and Shell environments are available for child shells.

When I want to permanently add current directory to PATH I can do it in 2 ways:

1-Normal way:

 [sinoosh@localhost ~]$ vi ~/.bash_profile 

enter image description here

2-without export command

enter image description here

And then logout i see the same result as normal way

enter image description here

there is not different between "1"&"2" . can we say the export command is useful for that time we do not want permanently add to environment variables?

What's happening here?

  • 1
    Please note that setting or changing environment variables in ~/.bash_profile does not affect the graphical environment on a desktop. Therefore I wouldn't call it the "normal way". Please take a look here: help.ubuntu.com/community/… Sep 25, 2016 at 15:52

1 Answer 1


The export (or declare -x) declaration makes the difference between a plain shell variable and an environment variable.

Since PATH is almost certainly already part of your environment - having been set in /etc/environment for example - marking it for export a second time isn't strictly necessary[1] (although it does no harm - and make the intent clear).

1 at least I think that's the case - I'd like to find a primary reference

  • thank you, i think the reason is first time PATH is exported in /etc/profile but i am not sure
    – Sinoosh
    Sep 25, 2016 at 13:06
  • 1
    PATH is made an environment variable early (more early than via /etc/profile, @Sinoosh) , and yes, it's not needed to export it again after that. This can possibly be derived from the community wiki page EnvironmentVariables, but it isn't expressed very clear. Sep 25, 2016 at 15:44
  • according to the book of Ross Brunson in login shell sessions we have these steps:1-loging to shell. 2-/etc/profile is sourced 3-/etc/profile.d are sourced 4-~/.bash_profile is sourced 5-~/.bashrc is sourced from within the ~/.bash_profile 6-user conducts her business 7-exit 8-.bash_logout is sourced. do these steps are not complete?
    – Sinoosh
    Sep 25, 2016 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.