[Gllug] Re: Bash Data validation libraries

Richard Jones rich at annexia.org
Tue Feb 14 15:21:29 UTC 2006


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.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list