Linux Basic Course David

pls can someone explain how the environment variable works and how it can be made persistent

Are you referring to environment variables in bash?

yes i am. Can you shed a bit of light on it? Thanks

Google around for the .bashrc file. Every time a shell is started, it looks for a ‘run configuration’ file. In such a file, you can type commands that will be executed before you get the first prompt. Typically, they are used to configure aliases, some small utility functions or to set environment variables.

For bash, the run configuration file is at ~/.bashrc. Try adding a line like this:

export MY_AWESOME_VAR="Hello, Bash!"

If you do that, and export your file, the MY_AWESOME_VAR should be available in your shell:

Hello, Bash!

Lastly, note that every shell has it’s own run configuration file. So your settings in .bashrc won’t do anything if you’re using zsh, sh, fish, csh, …

Now, environment variables don’t have to be set in these rc (run configuration) files. You can just configure them on-the-fly as well. E.g.:


$ MY_OTHER_AWESOME_VAR="Hello, Universe!"
Hello, Universe!

In this case, once you close the shell, the value for MY_OTHER_AWESOME_VAR will be lost.

At any point, you can also check which environment variables are available at that moment. Just run env in your shell to see a full list.

I hope that clarified smth :slight_smile:

1 Like

Thanks for sharing @HerrSubset.

1 Like

it helped. Thanks so much for the explanation

1 Like