19. Environmental variables - muneeb-mbytes/linux_course GitHub Wiki
Environmental_Variables
In Linux based systems environment variables are a set of dynamic named values, stored within the system that are used by applications launched in shells
or subshells.
Fig-1: All variations of environmental variables
Cheat sheet for environmental variables variations:
Sr.no | Environmental variables with different variations | description |
---|---|---|
1 | printenv | Used to displays all pre-defined and user created environmental variables. |
2 | setenv | Used to set a value or command to a variable. |
printenv command
This command is used to print the value assigned to an environmental variable or execute the command assigned to an environmental variable which is already created.
syntax
printenv
In the below Fig-2 you can see that first we had assigned an environmental variable 'sample ' with value 10 and then by giving printenv we can print the value which is assigned to the environmental variable 'sample' by us
before.
Fig-2: Usage of printenv command
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-1: giphy for printenv command
GitHub link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/environment_variables/printenv_value.csh
setenv command
This command is used to create an environmental variable which can store a value or a command which is defined by the user.
If setenv is given no arguments, it displays all environment variables and their values. If only VAR is specified, it sets an environment variable of that name to an empty [null] value. If both VAR and VALUE are specified, it sets the variable named VAR to the value VALUE.
The setenv
is similar to set
in bash
Syntax
setenv MYVAR myvalue
In the below Fig-3 we are creating an environmental variable 'sample' and assigning the value 10 for it. Now if we give $sample it will print the value which is 10 on the terminal.
Fig-3: Usage of setenv command
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-2: giphy for setenv command
GitHub link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/environment_variables/setenv.csh
To learn df and du command : https://github.com/muneeb-mbytes/linux_course/wiki/20.-df-and-du-command