I am looking to do something like this in KSH:
if (( $var = (foo|bar)[0-9]*$ )); then
print "variable matched regex"
fi
Is it possible at all?
For the record I'm using Ksh Version M-11/16/88i on a Solaris 10 machine.
|
I am looking to do something like this in KSH:
Is it possible at all? For the record I'm using Ksh |
||||
|
Ksh has regular expressions, but not in the usual syntax (not in the version in Solaris 10).
In the manual, look under “conditional expressions” for what's inside the brackets and under “file name generation” for the pattern syntax. |
|||
|
|
|
Using
Outputs:
|
||||
|
|
|
Why not use egrep(1)? Gives you all a regex user could wish for:
Additional note for Solaris: With Solaris you may want to check the manpage for egrep - there is annother egrep version that is located at |
|||||||||
|
|
I did something like this, using
|
||||
|
[foo|bar]means "match a single character from the set (a,b,f,o,r,|)"? If you mean "match 'foo' or 'bar'" you want(foo|bar)– glenn jackman Oct 19 '11 at 14:20