atupal
atupal

Reputation: 17210

Set a environment variable and make it effective in all opened terminal

I have many opened terminals. Now I want to set a environment variable and wish the environment variable can effective in all opened terminal(do'nt need lgout the shell and login again or any other extra command such as source to make it effective) not just the terminal in which I set the environment variable.

Is there any ideas?

Upvotes: 0

Views: 4310

Answers (1)

choroba
choroba

Reputation: 241868

It depends on the type of shell you use. For example, in bash, you can

  1. create a file ~/.env which will contain the settings.
  2. in your ~/.bashrc, tell each terminal to source the file at each prompt:

    PROMPT_COMMAND='. ~/.env'
    

If you change the .env file (e.g. try echo TEST=1 > ~/.env), then after pressing Enter in any terminal that uses the new .bashrc, echo $TEST will produce 1.

Upvotes: 5

Related Questions