maart@cs.vu.nl (Maarten Litmaath) (06/15/89)
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
andyc@hpopd.HP.COM (Andrew Cunningham) (06/21/89)
Usinh HP-UX 6.5 on a 9000/360, using date '+%H:%M:%S' prints the date, so use command substitution to get this into the variable you want us e: time=`date +%H:%M:%S` (sh) or set time = `date +%H:%M:%S` (csh) to get each component: hrs=`date +%H` min=`date +%M` sec=`date +%S` Hope this helps! Andrew Cunningham Disclaimer: I am NOT speaking as an employee of HP. Andrew Cunningham, HP Software Engineering Systems Division, Pinewood E-mail: andyc@hpopd hplabs!hpopd!andyc