[Gllug] RE: Gllug Digest, Vol 32, Issue 45

David Abbishaw David at Abbishaw.com
Tue Feb 14 20:02:26 UTC 2006



Date: Tue, 14 Feb 2006 15:21:29 +0000
From: Richard Jones <rich at annexia.org>
Subject: Re: [Gllug] Re: Bash Data validation libraries
To: Greater London Linux User Group <gllug at gllug.org.uk>
Message-ID: <20060214152129.GB26329 at furbychan.cocan.org>
Content-Type: text/plain; charset=us-ascii

On Tue, Feb 14, 2006 at 11:52:35AM +0000, David Abbishaw wrote:
> Mostly I want to be able to check user input, normally from a read 
> statement for things like, length, number of '.'s if there entering an 
> IP address or name.  That the only characters entered are a-z 0-9 as 
> when cuting and pasting from excel/word other non printable characted 
> can get pasted.

A lot of these things can be done fairly simply using the available
tools.  For instance, a naive check of IP addresses might be:

#!/bin/bash -

read ip
if [[ ! $ip =~
^[1-9][0-9]?[0-9]?\.[1-9][0-9]?[0-9]?\.[1-9][0-9]?[0-9]?\.[1-9]\[0-9]?[0-9]?
$ ]]; then
  echo "invalid IP address"
fi

Rich.


Thanks - that looks fantastic and I'll test that out tomorrow, that should
also work for default gateway and subnet mask.

Although I'm a little miffed that looks like a regular expression and I
thought that only worked in the latest Bash v3 whereas most distros have
bash v2.

Are there any good web resources where I can find other snippets like this?

Thanks
David



-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list