On Tue, 6 Feb 2001, Andrew So Hing-pong wrote:

> Hi all,
> 
> I would like to ask a question about regular expression & patten
> matching on the script writting.
> 
> test.sh
> ...
> if [ $1 != "v[0-9][0-9].[0-9][0-9].[0-9][0-9]" ] ; then
>    echo "Version must be vXX.XX.XX where X be a digit"
> else
>    echo "Version -> [$1]"
> fi
> 
> I want to ensure the $1 must v00.00.00 (an example), but the result
> 
> any comments ? 
> Thanks for your attention !/!

Try this:


if [ ! -z "${1##v[0-9][0-9].[0-9][0-9].[0-9][0-9]}" ]
then
    echo "Version must be vXX.XX.XX where X be a digit"
else
   echo "Version -> [$1]"
fi


or this for bash/ksh:


if [ "${1##v[0-9][0-9].[0-9][0-9].[0-9][0-9]}" ]
then
    echo "Version must be vXX.XX.XX where X be a digit"
else
   echo "Version -> [$1]"
fi


-- 
John Darrah (u05192)    | Dept: N/C Programming
Giddens Industries      | Ph: (425) 353-0405 #229
PO box 3190             | Ph: (206) 767-4212 #229
Everett  WA    98203    | Fx: (206) 764-9639



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to