?
Solved

check for existence of 2 command line variables

Posted on 2002-04-24
2
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 total points
ID: 6965729
if [[ -n "$1" && -n "$2" ]]; then
 
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:
Suggested Courses

719 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