BASH regex help
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Fri Apr 21 20:47:04 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
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//./\\./}
--
William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
--
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