How to refer to an script argumentSolutionRefer to a script
How to refer to an script argument?
Solution
Refer to a script argument:
An argument is a piece of information that a script or command uses.In majority cases it is either a number or a special word that stands for a number.
Script only need arguments if they are going to occur in a variety of situation.
Any shell script you run ,it inherits the enviromental variables accessible to its parent shell.
Any argument you type after the script name on the shell command line are passed to the script as a series of variables.
*Functions shell script variables:
1]All functions arguments can be accessed via $1,$2,....,$n.
2]$0 always points to the shell script name.
3]$* or $@ holds all arguments passed to functions.
4]$# holds the number of positional argumentspassed to the function.
*Following parameter are recognized to passing arguments to a shell script:
$*:Returns a single String (\"$1,$2,...,$n) compairing to all of posiyiona arguments seprated by internal field seprator.
$@:Return a sequence of string (\"$1\",\"$2\",...,\"$n\")where each positional arguments seprated from the other.
$1,$2,...,$n: Refer to the numbered arguments to the script,where n is the posiyion of arguments on the command line.
$0:Fefer to the name of script itself
$# : Refer to the number of arguments specified on a command line
Ex: Suppose we have to creat a shell script wuth name test
echo There are $# arguments to $0:$*
echo first argument:$1
echo second argument:$2
echo third argument:$3
echo here they are again:$@
When you execute this file you see somthing like below
$ test too me you
There are 3 arguments to test :too me you
first argument:too
second argument:me
third argument: you
here they are again :too me you
Where ,$# - expanded to the number of arguments to the script,$*& $@ - contain the entire argument list,$0 - Access Individual parameters ,which contains the name of the script & $1 to $3 - contain the arguments to the script.


