Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re^2: Getting UNIX time from the shell Message-ID: <2759@piraat.cs.vu.nl> Date: 14 Jun 89 20:11:40 GMT References: <1343@cbnewsh.ATT.COM> <810067@hpsemc.HP.COM> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 58 gph@hpsemc.HP.COM (Paul Houtz) writes: \... [comments deleted] \#!/bin/ksh \ \clock () { \CURTIME=`date | awk '{print $4}'` \print -n $CURTIME | \ awk 'BEGIN {FS = ":" }{if ($1 > 12) print $1-12 ":" $2 " pm" } \ {if ($1 <= 12) print $1 ":" $2 " am"}' \} \ \time=`clock` \ \day=`date | awk '{print $1 " " $2 " " $3 }'` \ \print -n "$day $time" 1) I reformatted the `print ... | awk ...' line: it was longer than 80 characters, totally unnecessary :-( 2) The following clock() avoids invoking awk twice, furthermore the script is enhanced: clock() { # in ksh the LOCAL parameters are set; in sh the GLOBAL ones set `date` echo $4 | awk '{ FS = ":" if ($1 > 12) print $1 - 12 ":" $2 " pm" else print $1 ":" $2 " am" }' } 3) I know Paul probably needs the clock() function elsewhere, but compare anyway: eval ` IFS=' :' set \`date\` echo day="'$1 $2 $3'" h=\`echo $4 12 - p | dc\` case $h in -* | 0) echo time="'$4:$5 am'" ;; *) echo time="'$h:$5 pm'" esac ` echo "$day $time" -- "I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam: they're small." (Stephen Savitzky) |maart@cs.vu.nl, mcvax!botter!maart