Re: [SLUG] need shell script routine

From: Eben King (eben1@tampabay.rr.com)
Date: Fri Feb 06 2004 - 15:38:42 EST


Oops, I forgot some stuff.

On Fri, 6 Feb 2004, Eben King wrote:

> #! /bin/pdksh
> typeset -Z2 TOTAL_SECONDS=0 TOTAL_MINUTES=0 TOTAL_HOURS=0
> TOTAL_DAYS=0
>
> for component_time in 1 2 3 4 ; do
> TOTAL_SECONDS=$((TOTAL_SECONDS + $(<extract seconds field>) ))
> TOTAL_MINUTES=$((TOTAL_MINUTES + $(<extract minutes field>) ))
> TOTAL_HOURS=$((TOTAL_HOURS + $(<extract hours field>) ))
> <that's all folks> && break
> done
>
> while [[ $TOTAL_SECONDS -ge 60 ]] ; do
> TOTAL_MINUTES=$((TOTAL_MINUTES + 1))
 TOTAL_SECONDS=$((TOTAL_SECONDS - 60)
> done
>
> while [[ $TOTAL_MINUTES -ge 60 ]] ; do
> TOTAL_HOURS=$((TOTAL_HOURS + 1))
 TOTAL_MINUTES=$((TOTAL_MINUTES - 60))
> done
>
> while [[ $TOTAL_HOURS -ge 24 ]] ; do
> TOTAL_DAYS=$((TOTAL_DAYS + 1))
 TOTAL_HOURS=$((TOTAL_HOURS - 24))
> done
>
> prefix=
> [[ $TOTAL_DAYS -gt 0 ]] && prefix="$TOTAL_DAYSd"
>
> echo "$prefix TOTAL_HOURS:TOTAL_MINUTES:TOTAL_SECONDS"
> exit 0

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar

"You're one of those condescending Unix computer users!" "Here's a nickel, kid. Get yourself a better computer" - Dilbert.

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:33:09 EDT