Which of the following is used for storing the number of positional parameters?

Which of the following is used for storing the number of positional parameters?
A. $n
B. $#
C. $*
D. $2
 
Answer: b
Explanation: $# is used for storing the number of arguments specified. It lets us design scripts that check whether the right number of arguments have been entered. For example, the following script shows the use of positional parameters:
Code:
#!/bin/sh                
# emp.sh
echo “ The number of arguments specified are $#
The arguments are $*”
Now execute the script:
$ emp.sh  director.lst            // director.lst is command line argument given to the script.
The number of arguments specified is 1
The arguments are director.lst
 

Tìm kiếm

Back
Top