Variables in Linux Programming

Variables are an important part of any program or script.a variable is an element to refer block of data in memory that can be modified.a linux or unix variable can be assigned any type of value,such as text string or number.in linux there are two type of variables.

System Variable

An environment variable is a variable that is available to any child process of shell.usually,these variables are defined and needed by the programs that it runs,it is created and maintained by the linux itself.this type of variable defined in Capital letters.some of the system variables are shown below.

Variable

Example

Descriptions

BASH_VERSION

echo $BASH_VERSION

Holds the version of this instance of bash.

HOSTNAME

echo $HOSTNAME

The name of the your computer.

CDPATH

echo $CDPATH

The search path for the cd command.

HISTFILE

echo $HISTFILE

The name of the file in which command history is saved.

HISTFILESIZE

echo $HISTFILESIZE

The maximum number of lines contained in the history file.

HISTSIZE

echo $HISTSIZE

The number of commands to remember in the command history. The default value is 500.

HOME

echo $HOME

The home directory of the current user.

IFS

echo $IFS

The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is .

LANG

echo $LANG

Used to determine the locale category for any category not specifically selected with a variable starting with LC_.

PATH

echo $PATH

The search path for commands. It is a colon-separated list of directories in which the shell looks for commands.

PS1

echo $PS1

Your prompt settings.

TMOUT

echo $TMOUT

The default timeout for the read builtin command. Also in an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the command. If not input provided it will logout user.

TERM

echo $TERM

Your login terminal type.

SHELL

cho $SHELL

Set path to login shell.

DISPLAY

echo $DISPLAY

Set X display name

PWD

echo $PWD

current working directory

USERNAME

echo $USERNAME

Shell name

User Defined Variable

Shells also allow you to create your own variables for use within scripts (local variables) and to pass between scripts (global variables). User variables are traditionally created using lower-case characters.

To create a variable merely choose a lower-case name for the variable and give it a value using an equal (=) sign. Make certain that there are no spaces on either side of the equal sign. You can use the unset command to nullify the value of a previous set variable. Here are some examples.

Syntax

variable_name = value


$a = 10
echo $a						
							

defined string variable in linux the following example


$company ='Veewom Technology'
echo $company;

							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!