Jan 27, 2003 #1 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.
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.
Jan 27, 2003 #2 dickiebird Programmer Feb 14, 2002 758 GB 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 (-))) Upvote 0 Downvote
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 (-)))
Jan 27, 2003 #3 J1mbo Programmer Dec 12, 2002 93 US 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 Upvote 0 Downvote
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
Feb 4, 2003 #4 gregor weertman Programmer Sep 29, 2000 195 NL [ -z "${variable#[0-9]}" ] && echo variable is a number. regards Gregor. Gregor.Weertman@mailcity.com Upvote 0 Downvote
[ -z "${variable#[0-9]}" ] && echo variable is a number. regards Gregor. Gregor.Weertman@mailcity.com