Solved

check for existence of 2 command line variables

Posted on 2002-04-24
2
219 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now