Solved

check for existence of 2 command line variables

Posted on 2002-04-24
2
223 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:lphillips120898
2 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 6965725
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.
0
 
LVL 5

Accepted Solution

by:
ecw earned 50 total points
ID: 6965729
if [[ -n "$1" && -n "$2" ]]; then
 
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question