Hello,
Pls explain the difference between $# and $@, and how its used in shell scripting .
Thanks in advance
Hello,
Pls explain the difference between $# and $@, and how its used in shell scripting .
Thanks in advance
In short, RTFM.
Under Special Parameters in man sh
@ Expands to the positional parameters, starting from one. When
the expansion occurs within double quotes, each parameter
expands to a separate word. That is, "$@" is equivalent to "$1"
"$2" ... When there are no positional parameters, "$@" and $@
expand to nothing (i.e., they are removed).
# Expands to the number of positional parameters in decimal.
Thanks for the info, but its not clear to me can you explain me via an example......
An example to help you understand better.
$# - Will give you the number of arguments passed to the script
$@ - Will list all the arguments passed
/export/home/test/mons/UnixForum>cat test.sh
#!/bin/ksh
print "The number of arguments passed to this shell script is " $#
print "The arguments passed are as follows"
print "$@"
/export/home/test/mons/UnixForum>test.sh hai welcome to unixforum .com
The number of arguments passed to this shell script is 5
The arguments passed are as follows
hai welcome to unixforum .com
Thanks for the expalantion ......