Solved

check for existence of 2 command line variables

Posted on 2002-04-24
2
224 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 50 total points
ID: 6965729
if [[ -n "$1" && -n "$2" ]]; then
 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
aix tls version 6 653
Correct syntax to upload file in a script using sftp 2 110
unix in java example 9 88
swp file in unix 16 47
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

710 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