Link to home
Start Free TrialLog in
Avatar of lphillips120898
lphillips120898

asked on

check for existence of 2 command line variables

The following checks for the existince of one variable being passed on the command line, and exits if it isn't there:

if [[ -n $1 ]]; then
  print
else
  print
  print "   ** Enter Node Name (i.e. createServerGroup.sh SpherionServerGroup) **\n"
  exit 1
fi

How can I check for two variables being passed in the same if statment?

Thanks,

Lisa
Avatar of jlevie
jlevie

Why not check for the number of arguments first and then handle the cases of one or two args? $# will contain the argument count, so:

if [ $# = 2 ]; then
  # two args
elif [ $# =1 ]; then
  # only one arg
else
  # something I'm not prepared to deal with
fi

should do the trick.
ASKER CERTIFIED SOLUTION
Avatar of ecw
ecw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial