bashenvironment-variablesubuntu-16.04

How can I set a variable permanent for a non-terminal session (Bash)?


I want to use my own specific variable KILL, but I can't find a way to make it visible for non-terminal session.

By now I tried to add KILL=0 and export KILL=0 to ~/.profile, but that doesn't seem to work (when I tried to echo KILL into some txt file, it showed empty lines only, example - echo $KILL >> test.txt).

What should I do to make my variable visible for non-terminal sessions?


Solution

  • On Linux, using Bash, you will need to put the variable into ~/.bash_profile. Then it will be available when you open a new terminal where you would launch echo $KILL. After you re-login, it should be available to any process you launch even outside terminal as long as it's going to try to use it.

    The variable can be also put in /etc/profile (to be set for all users) or /etc/environment (to be set for all users and processes started by the system).