The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-18-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,886
With egrep:

Code:
printf "%s\n" "$decimal"|egrep '^[0-9]+(\.[0-9][0-9])?$' >/dev/null && echo OK||echo KO
Or (with not too old versions):

Code:
printf "%s\n" "$decimal"|egrep -q '^[0-9]+(\.[0-9]{2})?$' && echo OK||echo KO
With bash3(and ksh93?):

Code:
[[ "$decimal" =~ ^[0-9]+(\.[0-9]{2})?$ ]]&&echo OK||echo KO
Of course, you should modify it a bit, if you want
.00 and 00. to be considered OK.