[comp.unix.questions] another way

merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) (03/31/89)

In article <1177@Portia.Stanford.EDU>, karish@forel (Chuck Karish) writes:
| 	set `date | tr ':' ' '`
| 	hr=$4
| 	min=$5
| 	sec=$6
| 
| 	If that's not ugly enough for you, use this instead:
| 
| 	expr "`date`" \: ".*\([ 	0-9][0-9]:..\):.*"

For the truly ugly (and no additional processes), try:

oldIFS="$IFS" IFS=": "; set - `date`; hr=$4 min=$5 sec=$6 IFS="$oldIFS"

Amazing what /bin/sh can do for you if you let it. :-)
(I'm trying to write EMACS in /bin/sh... anyone want to help? :-)

Just another UNIX hacker,
-- 
/     Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095        \
|        on contract to BiiN (for now :-) Hillsboro, Oregon, USA.             |
|<@intel-iwarp.arpa:merlyn@intelob.intel.com> ...!uunet!tektronix!biin!merlyn |
\     Cute quote: "Welcome to Oregon... home of the California Raisins!"      /

john@frog.UUCP (John Woods) (04/04/89)

In article <4259@omepd.UUCP>, merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) writes:
E> In article <1177@Portia.Stanford.EDU>, karish@forel (Chuck Karish) writes:
l> | 	set `date | tr ':' ' '`
e> | 	hr=$4
g> | 	min=$5
a> | 	sec=$6
n> | 	If that's not ugly enough for you, use this instead:
c> | 	expr "`date`" \: ".*\([ 	0-9][0-9]:..\):.*"
e> For the truly ugly (and no additional processes), try:
.> oldIFS="$IFS" IFS=": "; set - `date`; hr=$4 min=$5 sec=$6 IFS="$oldIFS"

For the truly elegant (with no additional processes), scarf up the date.c
I just posted to comp.unix.questions and alt.sources (if you don't have
a System V date command), and try

	eval `date '+hr=%H min=%M sec=%S'`

-- 
John Woods, Charles River Data Systems, Framingham MA, (508) 626-1101
...!decvax!frog!john, john@frog.UUCP, ...!mit-eddie!jfw, jfw@eddie.mit.edu

			Remainder Khomeini!