[Gllug] Arithmetic error in bash on 08 and 09?

Liam Delahunty liamvictor at gmail.com
Mon Jul 26 11:17:51 UTC 2004


Thanks all,

going back to my original problem of removing 1 from the hour and then
grepping the time in a log file I've come up with the following.

add_leading_zero ()
{
 if [ ${#1} = "1" ]; then       # string length = 1
  pad="0"${1}
 else
  pad=${1}
 fi
 return $pad
}

today=`date "+%b %d"`
ph=`date "+%H"` # Get hour. ph = PREVIOUS HOUR

num=$((10#$ph - 1))     # it's base 10. Take away 1
add_leading_zero $num   # add zero for grep!

then=$today" "$pad
echo $then
..rest of script..

Thanks again. 

-- 
Kind regards, Liam Delahunty
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list