1833016 Members
3594 Online
110048 Solutions
New Discussion

number of parameters

 
SOLVED
Go to solution
Steve Sauve
Frequent Advisor

number of parameters

Hello all,

I am creating a script in which a variable number of parameters will be given when it is called. I seem to remember there being a variable that contains the number of parameters passed (though I could be making that up :). If it exists does anyone know what the variable is?
I guess my other option is just to count up through the parameter variables ($1, $2, $3, etc) and check for a value. But if there is a variable I can use I'd prefer to do it that way.

Thanks,
Steve
4 REPLIES 4
Sridhar Bhaskarla
Honored Contributor
Solution

Re: number of parameters

Hi Steve,

Are you talking about $# ? - the number of variables supplied

#!/usr/bin/ksh
print $#


-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Jeff Machols
Esteemed Contributor

Re: number of parameters

the variable is $#
Vincent Farrugia
Honored Contributor

Re: number of parameters

The variable is $#

HTH,
Vince
Tape Drives RULE!!!
Craig Rants
Honored Contributor

Re: number of parameters

As you can probably see, $# is the answer you are looking for. Do you have the Unix in a Nutshell book? Page 4-8 has all the built-in shell variables for sh and ksh. If you don't have it, then I would recommend getting it asap. bookpool.com has a great price, you won't regret getting this book.

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut