tobold.org

correct • elegant • free

△ comp.unix.shell △

◅ A bit of a grep stumper

dynamically assigning multiple variabels at once ▻

timer script

In article <3819D0B2.7FE3D3D3@op.net>, Daniel Frazier  <dfrazier@op.net> wrote:
>SEC=`expr $TIME % 3600 % 60`

I think you'll find :-) that this is equivalent to:

    SEC=`expr $TIME % 60`

>        echo -n "$HRS hrs. "

`echo -n' isn't very portable.  Really.

>        elif [ $HRS -gt 0 ]
>        then
>                echo "and $SEC secs."
>        else
>                echo "$SEC secs."
>        fi

If you really want this style of output, this is probably the best way
to do it.  But there's ancient Unix wisdom which says "always assume the
output of your program will be the input to another program".  (This
wisdom is often ignored, unfortunately, with `ls -l' being the canonical
bad example.)

So avoiding `echo -n', and giving a more predictable output format, I'd
write this:

    printf 'Elapsed time: %.2d:%.2d:%.2d\n' $HRS $MIN $SEC

which will produce output like this:

    Elapsed time: 00:02:15

Tim.
--
Tim Goodwin   | "People think [ W. Gibson is ] hi-tech because his prose
Leicester, UK | is as pleasant to read as a C++ program." -- JT

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.unix.shell
Subject: Re: timer script
Date: 2 Nov 1999 16:30:09 -0000
Organization: University of Leicester, UK
Message-ID: <7vn3j7$729$1@ltpcg.star.le.ac.uk>
References: <3819D0B2.7FE3D3D3@op.net>

△ comp.unix.shell △

◅ A bit of a grep stumper

dynamically assigning multiple variabels at once ▻