The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 09-04-2001
sam_pointer sam_pointer is offline
Registered User
 

Join Date: Jun 2001
Posts: 35
Regular Expressions in shell scripts <yawn>

Quite possibly a simple problem who's answer is evading me:

I am trying to write a sh shell script, part of which is *logically* trying to do the following:

if [ $1 = [A-Za-z] ]; then
...
fi

if [ $1 = [0-9.] ]; then
...
else
...
fi

Where the 1st condition is looking for a hostname passed as $1, the second a dotted-quad ip address, and the 3rd a catch-all error condition.

I cannot work out how to use regex with the test ([) command. Would $1 always evaluate to "TRUE"? And therefore I would use something like:

if [ $1 -a regex ]; then
...
fi

or not?
BTW: I know the regex I have given in the example are not water-tight for their application ([0-9.] doesn't necessarily guarantee a dotted-quad by any means), this is a tool which is only going to be used by myself, and therefore isn't too much of a problem

If someone would like to supply the regex for a dotted quad I would be most greatful :-), but no sweat.

Thanks in advance.
Forum Sponsor