Environment Variables

·

1 min read

You can run printenv or env in your terminal

1)How to set Environment variables:-

myVAR=hello

printenv myVAR=hello OR echo $myVAR

2)How to unset it?

unset myVAR then echo $myVAR

3)If you type export myVAR=hello then you can do echo $myVAR

You can add this line in user profile. The tilde symbol (~) represents the home directory.

a)~/.bash_profile (CentOS)

b)~/.bash (Ubuntu)

Add this line in any one of the file

export myVAR=hello

You can echo in new terminal but you won’t be able to echo in your current shell

To solve this, type source ~/.profile then it will show the output in your current shell.

But if you open in new tab in your current shell, then it won’t show the output.

Then add this line export myVAR=hello in ~/.bashrc