BASH regex help
Lennart Sorensen
lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Fri Apr 21 15:52:26 UTC 2006
On Fri, Apr 21, 2006 at 11:36:12AM -0400, Neil Watson wrote:
> 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//\./\\./}
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."
You wouldn't believe how many times I have made that mistake in bash. :)
Len Sorensen
--
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