|
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.
|