Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Oct 2001 12:26:53 -0700
From:      "Crist J. Clark" <cristjc@earthlink.net>
To:        Mike Meyer <mwm@mired.org>
Cc:        Randy Bush <randy@psg.com>, questions@FreeBSD.ORG
Subject:   Re: date of a file
Message-ID:  <20011013122653.B36620@blossom.cjclark.org>
In-Reply-To: <15304.21677.127685.628179@guru.mired.org>; from mwm@mired.org on Sat, Oct 13, 2001 at 09:50:21AM -0500
References:  <73720831@toto.iv> <15303.43126.44123.116068@guru.mired.org> <E15sJ9L-000Hfy-00@rip.psg.com> <20011013030023.M6274@blossom.cjclark.org> <15304.21677.127685.628179@guru.mired.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Oct 13, 2001 at 09:50:21AM -0500, Mike Meyer wrote:
> Crist J. Clark <cristjc@earthlink.net> types:
> > On Sat, Oct 13, 2001 at 12:23:59AM -0700, Randy Bush wrote:
> > > > date +%y%m%d-%H%M%S -jf "%b %d %H:%M:%S" `ls -lT filename | awk ' { print $6, $7, $8, $9 } '` 
> > > 
> > > i have tried many variations on this, and all fail as follows:
> > > 
> > >   rip.psg.com:/usr/home/randy> date -j +%y%m%d-%H%M%S -f '%b %d %T %Y' `ls -lT 2borg | awk '{print $6, $7, $8, $9}'`
> > >   date: illegal time format
> > >   usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
> > > 	      [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
> > > 
> > > yes, this all seems in accord with what 'man strftime' shows me.
> > 
> > It has to do with how date(1) reads the command line. Basically, the
> > '+ format' and '-f format date' options are not compatible. This
> > appears to be a bug, but it would be really tricky to
> > fix. (Hmm... maybe not...) Send in a PR if you would like so it gets
> > into the system. Have a look at date.c. It is pretty clear what is
> > happening. Feel free to submit a fix with a PR.
> 
> Considering that the man page says:
> 
>      -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.
> 
> It's *definitely* a bug. Randy, if you're not going to file a PR, let
> me know and I will.

I spoke too soon. It seems to be a problem with the way the shell
parses the command line. For example, a script like,

  #!/bin/sh

  DATE=`ls -lT $1 |  awk '{print $6, $7, $8, $9}'`

  date -j -f '%b %d %T %Y' "$DATE" +%y%m%d-%H%M%S

Works fine. date(1) is fine.
-- 
Crist J. Clark                     |     cjclark@alum.mit.edu
                                   |     cjclark@jhu.edu
http://people.freebsd.org/~cjc/    |     cjc@freebsd.org

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?20011013122653.B36620>