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

Stig Brautaset stig at brautaset.org
Mon Jul 26 11:32:11 UTC 2004


On Mon, Jul 26, 2004 at 12:17:51PM +0100, Liam Delahunty wrote:
> 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

This will break when $ph is 0, but you probably already knew that...

Stig
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list