Declared environment variable TEST=HELLO WORLD! . After closing the console, it is not available, how to save it permanently?

3 answers 3

If you want this variable to be not only in the current console, but also taken into account in programs, then you need to register it in .bashrc not as: TEST = HELLO WORLD !, and export TEST = HELLO WORLD! Then it will not be exported Only in the current shell, but also in all the others. It is easy to check:

 cat 1.sh #!/bin/bashecho $TEST$ TEST=HELLO$ ./1.sh 

There is nothing.

 $ export TEST=HELLO./1.sh HELLO 

The word HELLO appeared.

Also, if you're interested, read about the differences .profile, .bashrc, .bash_profile, .login.

  • @ aza1io1.sh is some kind of system file? That's what gives me after using the export root @ Server command: ~ # export TEST = HELLO ./1.sh-bash: export: `./1.sh ': wrong id - zsiteru
  • @zsiteru I created it myself. I wrote in it: \ #! / bin / bashecho $ TEST filled out chmod + x 1.sh so that it becomes executable. - azalio

write it in ~ / .bashrc

    If you want a new permeny to be global and always accessible to all applications, then you can write it in / etc / environment