csh -> Bourne conversion

DanieLouiSmith daniel at island.uu.net
Mon Jan 23 06:56:56 AEST 1989


[I'm cross-posting this to comp.unix.questions, because a tangent off
this question seems worth mentioning to a larger group of people]

In article <RCARDENA.89Jan20003352 at hqpyr1.oracle.com> rcardena%oracle.uucp at hplabs.hp.com writes:
>Quick question - in a csh script, I can reformat a date from the
>standard "Fri Jan 20 00:29:26 PST 1989" to "20-Jan-1989" by saying
>
>	set date = `date`
>	set date2 = $date[3]-$date[2]-$date[6]
>
>Any way to do this with the Bourne shell?

	Here's a way that assumes your "date" command will handle formatting
options.  It will only work for the next 11 years, and then you'll need
to change "19" to "20" :-)

	$ date=`date +%d-%h-19%y`

	Actually, this brings up a point that programmers everywhere should
start thinking about:  all of those hardcoded "19"'s in programs are going to
be useless in the year 2000.  Think of all the shell scripts/programs
like the command above...perhaps using a variable or adding a format
to the date command (I notice that 'Y' isn't being used...a quick patch
to date would make it so that 'Y' would give you all four digits) would be
better, such as "date +%d-%h-$CENTURY%y" or "date +%d-%h-%Y".

	I don't think it's too early to point this out...good shell scripts,
once written, may not be looked at again for years...they might
be invoked nightly from cron (8), and are all but invisible as far as
what you work on day to day...it'll save some grief later if people
start doing The Right Thing now :-)

				dan
-- 
    /na/usa/ca/marin/SanRafael/94903/4000CivicCtrDr/IslandGraphics/DanSmith
daniel at island.uu.net  unicom!daniel at pacbell.com  {lll-crg,apple}!well!dansmith
ph: +1 415 332 FAST(h) 491 1000(w) 491 0402(Fax)  d: Island's coffee is laced
my mind likes cyberstuff, my hands guitar, my stomach pizza, and my feet skis



More information about the Comp.unix.questions mailing list