In Linux environment variables define the system behavior. Environment variables are present in all operating systems like Linux, Mac, Windows, etc. Environment variables are the same as variables. We can declare, recall and set them with the same syntax that we use for variables.
We refer to environment variables by daemons and applications whenever we require them. We use environment variables to revoke the default settings, and with the help of environment variables, we can handle system settings. In this Linux environment variables blog, we will discuss how to set environment variables and how to use them.
In this blog, we discuss the following topics:
A variable acts as a location to store the value, and that value can be text, filename, and number. Generally, we refer to its representative name that we provide while creating it. The value we store in that variable can be displayed, edited, deleted.
If you want to enrich your career and become a professional in Linux, then visit Mindmajix - a global online training platform: "Linux Certification Training" This course will help you to achieve excellence in this domain. |
Linux Environment variables are the dynamic values that impact the programs or processes on the computer. Environment variables are present in all the operating systems, but data types may differ. Environment variables provide information about system behavior.
[ Related Article: File Permissions in Linux ]
System Administrators have the capability for changing the environment variables to meet individual or greater group requirements of the users inside their environments. Administrators can change the command-line prompt, hostname.
Syntax: Unset variable name
Example:$unset $VAR1
Lern Top Linux Interview Questions And Answers |
To demonstrate the difference between environment and shell variables, we will start setting the shell variables.
To create a shell variable with the name “VAR1” and value “environment,” we have to enter:
$VAR1=’environment’
We can check variable is set through “echo $MY_VAR” of refining the set command output with grep set | grep VAR1:
$echo $VAR1
We use “printenv” variable for checking whether this variable is an environment variable or not.
$printenv VAR1
We can also attempt to print variable in the sub-shell, and we will retrieve an empty output:
$bash -c ‘echo $VAR1’
If you attempt to print the variable in the sub-shell then we will get the variable name displayed on our terminal:
$bash -c ‘echo VAR1’
We can also set the environment variables in one line:
$export “NEW_VAR1” =” NEW VAR1”
[ Related Article: What is Linux? ]
Following are some of the important environment variables
1. USER: Currently logged-in user.
Example:
$echo $USER
2. EDITOR: This is the default file editor. We use this editor when we type “edit” in the terminal.
3. HOME: This is the home directory of the current user.
Example:
$echo $HOME
/c/user/home
4. LOGNAME: This variable represents the current user.
5. SHELL: This variable represents the shell of the current user.
6. TERM: This variable represents current locales settings.
Example:
$echo $TERM
pterm
7. LANG: This variable represents the current locale settings.
8. PATH: The PATH environment variable represents the directories list that to be searched while implementing the command. When we are executing a command, the system will explore the directories.
Example:
$ echo $PATH
/user/library/document/drive: /user/local/temp
9. MAIL: The MAIL environment variable represents the location where the current user stores his mail.
[ Related Article: Difference Between Linux vs Unix ]
To make the environment variables constant, we must define those environment variables in the configuration files of bash. In the Linux distributions, when we start a machine, we read the environment variables from the below files:
Leave an Inquiry to learn Linux Training in Bangalore
Linux Environment Variables are a group of dynamic values and applications that will use them to customize the system. We can declare and use them as general variables. Among various environment variables, we can use them based on our requirements. I hope this article provides you with the required information about environment variables.
If you have any queries, let us know by commenting in the below section.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Linux Training | Nov 23 to Dec 08 | View Details |
Linux Training | Nov 26 to Dec 11 | View Details |
Linux Training | Nov 30 to Dec 15 | View Details |
Linux Training | Dec 03 to Dec 18 | View Details |
Viswanath is a passionate content writer of Mindmajix. He has expertise in Trending Domains like Data Science, Artificial Intelligence, Machine Learning, Blockchain, etc. His articles help the learners to get insights about the Domain. You can reach him on Linkedin