slicing the date

Dennis Pelton CSM Contractor x8876 dgp at ncsc1.AT&T.NCSC
Thu Mar 30 01:57:14 AEST 1989


In article <216000010 at s.cs.uiuc.edu>, carroll at s.cs.uiuc.edu writes:
> 
> Allright, I can't figure this out. I'm trying to put the current system
> time in my prompt. Under SysV, I can use 'cut' to pick out the seperate
> hours, minutes, and seconds from 'date'. For non-SysV types, 'cut' lets
> you pick out fields using either delimiter characters or absolute column
> counts. I found a way to do this using Ksh (with the pattern matchers),
> but it is very ugly. The question is, how can I cut up the output of
> date to put the hours, minutes, and seconds into seperate variables? Thanks!
> 
> Alan M. Carroll          "And then you say,
> carroll at s.cs.uiuc.edu     We have the Moon, so now the Stars..."  - YES
> CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll

OK, here's one way:

     hrs=`date +'%H'`
     min=`date +'%M'`
     sec=`date +'%S'`

Andhere's another:

     date +'%H %M %S' >now
     read hrs min sec <now

And a follow-up question for those who know more than I:  Why is it that
the following does NOT work?  The variables are empty.

     date +'%H %M %S' | read hrs min sec

Dennis Pelton
att.COM.UUCP!ncsc5!dgp



More information about the Comp.unix.questions mailing list