Tuesday, 21 June 2011

System Variables and Wild cards in Shell


We saw how to use user defined variables in the previous blog. Now, we take a look at some system variables predefined in the shell.
These variables are created and maintained by the linux kernel itself. They are always in capital letters.
To see the values of this variables we can use the echo command as follows







The shell even as some built in variables but before discussing that we first see what are wild cards.
Wild cards are short hand characters for other characters or strings.These are the standard wild cards available on linux.

[..-..] A pair of characters separated by a minus sign denotes a range.

For example



Lets see the inbuilt variables in shell enviournment.

We can pass command line arguments to shell just like in Java where the they are stored the an array generally named as args[]. In shell however they are accessed using $. An example script to clearly illustrate this fact.

In the first case output shows that first and second are the two arguments passed hence the value of $# is two. $* is an array of all the arguments passed. $1, $2 are used to access the first and second argument respectively. This access method can be extended to the n th variable.

The statement expr 1 + 1 does the arithmetic addition of 1 + 1 and runs the process in background. After the execution of the script the terminal shows the output of the expression and waits indefinitely since it is another process altogether.









No comments:

Post a Comment

Popular Posts