Home > Net >  Environmental variables are not reloading properly
Environmental variables are not reloading properly

Time:10-11

I really don't know how this could happen. So suppose I added the following line to my ~/.bashrc file: export asd='asd'

if I now save and reload the terminal: exec bash and I check for the value, it exists:

$ echo $asd
asd

All fine and jolly, but when I delete this value, when I remove the line export asd='asd', and create a new bash instance, the value persists.

I can modify the value just fine..

CodePudding user response:

global variables are passed to child processes.

[~] export asd='Hello World'
[~] sh
@sh-5.1$ echo $asd
Hello World

Doesn't matter if you remove that command from bashrc as long it is set in your enviroment, instead you will need to remove that global variable first. You can list all active global variables with env or printenv of your active bash-session.

[~] export asd='Hello World'
[~] env | grep asd
asd=Hello World
[~] unset asd
[~] sh
@sh-5.1$ echo $asd

Alternative you can start a new shell without invoking it from the previous shell. This way it will read your profile and bashrc only and not transfer any environment variables that are created/active for the (sub)shell you were using.

  • Related