case command and regex
Daniel Wayne Armstrong
daniel-HRJVlgn2G/y5aS82P/H3Zg at public.gmane.org
Sun Mar 17 00:15:49 UTC 2013
I am trying to write a usable regex for the case command in a shell
script. For example:
---
#!/bin/bash
# testscript $1
if [[ $1 =~ [\+\-]([0-9]+)+$ ]]; then
echo "Match is $1"
else
echo "No match."
fi
while [ $# -gt 0 ]; do
case $1 in
[\+\-]\([0-9]+\)+$ ) echo "Match is $1"
exit
;;
* ) echo "No match."
exit
;;
esac
done
---
... and if I run "./testscript +77" I get:
Match is +77
No match.
I know I have the syntax messed up somehow in the case regex example
but I have tried it many different ways and can't seem to get it
right. I have tried extglob as well and no joy.
If anyone could see what I am missing it would be greatly appreciated! Thanks!
--
(o< .: per curiositas ad astra .: http://www.circuidipity.com
(/)_
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list