S scan macrumors 6502 Original poster Oct 24, 2005 344 0 Feb 15, 2006 #1 When running a script whats a way to check whether arguments are being passed?
balamw Moderator emeritus Aug 16, 2005 19,365 980 New England Feb 15, 2006 #2 scan said: When running a script whats a way to check whether arguments are being passed? Click to expand... echo? e.g. echo $1. B
scan said: When running a script whats a way to check whether arguments are being passed? Click to expand... echo? e.g. echo $1. B
S scan macrumors 6502 Original poster Oct 24, 2005 344 0 Feb 15, 2006 #3 balamw said: echo? e.g. echo $1. B Click to expand... i want to check if there was argument(s) passed
balamw said: echo? e.g. echo $1. B Click to expand... i want to check if there was argument(s) passed
Doctor Q Administrator Staff member Sep 19, 2002 40,228 8,737 Los Angeles Feb 15, 2006 #4 $# 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.
$# 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.