BASH regex help

Neil Watson tlug-neil-8agRmHhQ+n2CxnSzwYWP7Q at public.gmane.org
Fri Apr 21 15:36:12 UTC 2006


I am trying to parse a string in BASH. I have two goals. First, exit if the
string contains anything other than 0-9, a-z or '.'. Second escape all '.' to
'\.'.

        # Check for a proper url
        if [[ $DOMAIN = [^a-b0-9\.] ]] ; then
                echo "Invalid URL  a-b, 0-9 and . allowed only."
                exit 1  
        fi

        # We must escape special characters
        $DOMAIN = ${DOMAIN//\./\\./}


Alas, my code does not work as I had hoped. The first test always passes even
if DOMAIN contains other characters. The second test tries to open a file. It
returns the error "No such file or directory."

-- 
Neil Watson             | Gentoo Linux
System Administrator    | Uptime 1 day
http://watson-wilson.ca | 2.6.11.4 AMD Athlon(tm) MP 2000+ x 2
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list