What is the difference between export, set and edit . bash_profile?

Asked

Viewed 137 times

3

I currently use three ways to define environment variables on linux or Mac, because I don’t know what the difference is between 3, someone can explain to me?

1 answer

4


First you better understand how the terminal works, I will explain below what actually happens in a very simple way.

When you use the EXPORT or the SET directly in the terminal/console, the values are stored directly in the current session of that terminal, that is, at the end of the session these values are lost.

The archive .bash_profile has its terminal pre-loading settings, so the environment is already prepared to use the variables defined and is valid in all sessions created from the terminal. When the file .bash_profile is not found he will try for .bash.

  • ~/.profile is the place to put things that apply to your whole session, as programs you want to start when you log in (but not graphics programs, they enter a different file) and definitions of environment variables.

  • ~/.bashrc is the place to put things that apply only to bash, such as alias and function settings, shell options and prompt settings. (You can also put the keys there, but they usually go into ~/. inputrc.)

  • ~/.bash_profile can be used instead of ~/. profile, but it is read only by bash, not by any other shell. (This is primarily a concern if you want your startup files to work on multiple machines and that your login shell is not a success at all of them.) This is a logical place to include ~/. bashrc if the shell is interactive. I recommend the following content in ~/. bash_profile:

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.