In Unix, there are two types of shell variables:
- System variables: Created and maintained by Unix itself. This type of variables will be defined in CAPITAL LETTERS.
PATH, HOME etc..
- User defined variables: Created and maintained by user. This type of variables will be defined in lower letters.
a, sum etc..
Examples of Systems Variables
You can print any of the above variables contains as follows:
- $ echo $USERNAME
- $ echo $HOME
To print the value of num echo $num
- To define variable called ‘vech’ having value Bus:
- To print contains of variable ‘n’ type command as follows:
- $ echo $num
- $ echo vech # prints ‘vech’ instead its value ‘Bus’
- $ echo num # prints ‘num’ instead its value ‘10’
- You must use $ followed by variable name.
Variables containing more than one word:
- Often a variable has a value that contains space characters in it. If you try to set a variable containing spaces in the normal way, you will get an error message as follows.
- You should always use double quotes for the variables which has more than one word.
- $ NAME=Mike Ron
- sh: Ron: not found.
- $ NAME=”Mike Ron”
- $ echo $NAME
- Mike Ron