What are Linux Variables And It's Types?
Linux Shell Scripting

What are Linux Variables And It’s Types?

When you started to learn about shell scripting or learning Linux, you will face the word Linux variables and these variables really important to in shell programmer career and make life easy for Linux admin. To process any data/information, computers keep that data in RAM.

RAM is divided into small locations(registers/block), and each location had a unique number called memory location/address, which is used to hold our data. Shell scripter or programmer can give a unique name to this memory location/address called memory variable or variable (It’s a named storage location that may take different values, but only one at a time).

In Linux (Shell), there are two types of variable:
(1) System variables – Created and maintained by Linux itself. This type of variable defined in CAPITAL LETTERS.
(2) User defined variables (UDV) – Created and maintained by the user. This type of variable defined in lower letters.


You can see system variables by giving a command like a $ set, some of the important System variables are:

System Variable
Meaning
BASH=/bin/bash Our shell name
BASH_VERSION=1.14.7(1) Our shell version name
COLUMNS=80 No. of columns for our screen
HOME=/home/vivek Our home directory
LINES=25 No. of columns for our screen
LOGNAME=students students Our logging name
OSTYPE=Linux Our Os type
PATH=/usr/bin:/sbin:/bin:/usr/sbin Our path settings
PS1=[\[email protected]\h \W]\$ Our prompt settings
PWD=/home/students/Common Our current working directory
SHELL=/bin/bash Our shell name
USERNAME=vivek Username who is currently log in to this PC

NOTE that Some of the above settings can be different in your PC/Linux environment. You can print any of the above variables contains as follows:

[[email protected] ~]# echo $HOME
/root
[[email protected] ~]# echo $SHELL
/bin/bash

You can print several variables values so easily on system screen and can also use them in your script to automate them.

Caution: Do not modify System variable this can sometimes create problems. If you still want to check then make sure then you should create a backup before performing any task.


Kapendra
Love to write technical stuff with personal experience as I am working as a Sr. Linux Admin. and every day is a learning day and Trust me being tech geek is really cool.
http://kapendra.com

Leave a Reply