environment variable in linux

How to set an environment variable in Linux? You must know how to set a variable in bash:

You can show its value using:

 

However, the bash variable is not an environment variable. The different between ordinary bash variable and environment variable is that environment variables can be accessed by programs started by bash while ordinary bash variables cannot. You can use the export command to convert an ordinary bash variable to an environment variable:

Note that do not use export $myvar, in which $myvar will be expanded to somevalue by shell before the export command is executed, so you are actually executing “export somevalue” which is not what you want.   You can combine the steps to create an bash variable and converting it to an environment variable into single step:

 

Posted in tips of hosting