Understanding variables
Let's learn about creating variables in a 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 add the prefix $
before the variable, for example:
$ echo person person $ echo $person Ganesh Naik
The unset
command can be used to delete the declared variable:
$ a=20$ echo $a$ unset a
The unset
command will clear or remove the variable from the shell environment as well.
Here, the set
command will show all variables declared in the shell:
$ person="Ganesh Naik"$ echo $person$ set
Here, using the declare
command with the -x
option will make it an environmental or global variable. We will find out more about environmental variables in the next section.
$ declare -x variable=value
Here, the env
command will display all environmental variables:
$ env
Whenever we declare a variable
, that variable
will be available in the...