Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate input parameter ??

Status
Not open for further replies.

try2222

Technical User
Dec 10, 2002
8
US
Hi all,

According to you, is it possible to check if the input parameters of a shell-script is numeric??.

If it's possible can you describe me precisely how to implement it????

Thanks in advance for any help or suggestion.

By to all.
 
One way ( there'll be better ones )
(Only works for positive integers)

if [ ${1} -gt 0 ]
then
echo is numeric
else
echo aint numeric
fi

This creates an error if non-numeric data is passed, so run the script with 2>/dev/null
HTH Dickie Bird (:)-)))
 
This ksh script tests for negative values and values with decimal places:

#! /bin/ksh
if [[ $1 = ?(-)?(.)[0-9]*?(.)?([0-9])[!A-Za-z] ]] ; then
print "is numeric"
else
print "is NOT numeric"
fi


-jim
 


[ -z "${variable#[0-9]}" ] && echo variable is a number.


regards
Gregor. Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top