Understanding variables
Let's learn about creating variables in shell.
Declaring variables in Linux is very easy. We just need to use the variable name and initialize it with the required content.
$ person="Ganesh Naik"
To get the content of the variable we need to prefix $
before the variable.
For example:
$ echo person person $ echo $person Ganesh Naik
The unset
command can be used to delete a variable:
$ a=20 $ echo $a $ unset a
The unset
command will clear or remove the variable from shell environment as well.
$ person="Ganesh Naik" $ echo $person $ set
Here, the
set
command will show all variables declared in shell.
$ declare -x variable=value
Here, the declare
command with the –x
option will make it an environmental or global variable. We will understand more about environmental variables in the next sessions.
$ set
Again here, the set
command will display all variables as well as functions that have been declared.
$ env
Here, the env
command will display all environmental variables...