Date: 07 Feb 2002 11:46:45 -0800 From: Ken McGlothlen <mcglk@artlogix.com> To: Brett Jackson <brett@bsduser.ca> Cc: questions@freebsd.org Subject: Re: using `date` in a script Message-ID: <873d0d5b2y.fsf@ralf.artlogix.com> In-Reply-To: <20020207120404.O7616-100000@bsduser.ca> References: <20020207120404.O7616-100000@bsduser.ca>
next in thread | previous in thread | raw e-mail | index | archive | help
Brett Jackson <brett@bsduser.ca> writes:
| I am having difficulty passing a variable to date(8) and have it spit out
| the data in the date format.
|
| for example:
| birthday=19450104
|
| >date -f ccyymmdd $birthday
|
| that is some ugly psuedocode, eh? Can I even do this?
Well, if I understand you correctly, you want to be able to pass in a date like
"19450104" and be able to print out the date in its normal format. Yes?
Well, for starters, you need the "-j" option. From the manpage:
-j Do not try to set the date. This allows you to use the -f flag
in addition to the + option to convert one date format to
another.
At this point, your script could read:
#!/bin/sh
BIRTHDAY=19450104
# Now print the date in standard Unix format. We need to add "0000" to
# represent midnight on the given date.
date -j ${BIRTHDAY}0000
The -f option isn't necessary in this case.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?873d0d5b2y.fsf>
