G33K-TRICKS - Your source to Tips and Tricks : Use of Dollar symbol "$" in Shell Scripts

Tuesday, February 19, 2013

Use of Dollar symbol "$" in Shell Scripts

I do keep on getting confused when it comes to shell script with "$" sign.
So finally I thought I should jot it down somewhere

$#  implies number of Arguments provided
E.g. if [[ $# -ne 2 ]]
It means, if the number of arguments passed are less then 2

$? tells the exit status of the last executed command

$@   is all of the parameters passed to the script. For instance, if you call ./someScript.sh foo barthen $@ will be equal to foo bar.

Also, $@ = $*

$1 implies the first argument passed

$2 imples the second argument passed.

And so on...

No comments:

Check Out the Latest Posts

Recent Posts Widget