Local and Global Linux Environment Variables
In computer programming, a global variable is one that can be used anywhere in the program, while a local variable is one that is defined in a function and can only be used in that function. Here’s an example - Global_var and local_var are the global and local variables:
Var Global_val=50;
Function Fun()
{
var local_var =20;
}
Linux environment variables can be global or local. Global environment variables are visible from a shell session and any child processes that the shell spawns, while local variables are available only in the shell in which they are created.
System environment variables use all uppercase letters to distinguish them from normal user environment variables.
How to Set a Local Linux Environment Variable
In the following example, local_var is only visible in the current shell:
local_var=edward
echo $local_var
Output:
edward
We can create a global environment variable using the export command:
export Global_var=Hello
bash
echo $Global_var
Finally, the output will be:
Hello

