Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
When running a script whats a way to check whether arguments are being passed?
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,795
7,537
Los Angeles
$# is the number of arguments passed.

For example, if myscript contains the line
Code:
echo $#
then you'd get this:
Code:
myscript
0
myscript all
1
myscript all your
2
myscript all your base
3
myscript all your base are
4
You can use a test like this:
Code:
[ $# -le 2 ] && exit 0
to exit if there are fewer than two arguments.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.