Q.46 . What is difference between $*, $@ , $_and $0?
$#
|
The number of arguments supplied to a script.
|
$*
|
All the arguments are double quoted. If a script receives two arguments, $* is equivalent to $1 $2.
The "$*" special parameter takes the entire list as one argument with spaces between
|
$@
|
All the arguments are individually double quoted. If a script receives two arguments, $@ is equivalent to $1 $2.
The "$@" special parameter takes the entire list and separates it into separate arguments.
|
$?
|
The exit status of the last command executed.
|
$0
|
Gives File Name
|
test.sh
#!/bin/sh
echo "File Name: $0"
echo "First Parameter : $1"
echo "Second Parameter : $2"
echo "Quoted Values: $@"
echo "Quoted Values: $*"
echo "Total Number of Parameters : $#"
Here is a sample run for the above script −
No comments:
Post a Comment