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:
If you want to enrich your career and become a professional in Linux, then visit Mindmajix - a global online training platform: "" This course will help you to achieve excellence in this domain.
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.
Visit here to learn Linux Training in Hyderabad
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.
Leave an Inquiry to learn Linux Training in Bangalore
Unset variable name
[ Related Article: Advanced Linux Interview Questions ]
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:
We can check variable is set through “echo $MY_VAR” of refining the set command output with grep set | grep VAR1:
We use “printenv” variable for checking whether this variable is an environment variable or not.
We can also attempt to print variable in 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.
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.
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.
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.
$ echo $PATH
9. MAIL: The MAIL environment variable represents the location where the current user stores his mail.
[ Related Article: Difference Between Linux vs Unix in 2021 ]
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:
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.
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
|Linux Training||Sep 27 to Oct 12|
|Linux Training||Oct 01 to Oct 16|
|Linux Training||Oct 04 to Oct 19|
|Linux Training||Oct 08 to Oct 23|
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
Copyright © 2013 - 2022 MindMajix Technologies