2 # Get modification time of a file or directory and pretty-print it.
4 scriptversion
=2010-08-21.06
; # UTC
6 # Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005, 2007, 2009, 2010
7 # Free Software Foundation, Inc.
8 # written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # As a special exception to the GNU General Public License, if you
24 # distribute this file as part of a program that contains a
25 # configuration script generated by Autoconf, you may include it under
26 # the same distribution terms that you use for the rest of that program.
28 # This file is maintained in Automake, please report
29 # bugs to <bug-automake@gnu.org> or send patches to
30 # <automake-patches@gnu.org>.
32 if test -n "${ZSH_VERSION+set}" && (emulate sh
) >/dev
/null
2>&1; then
35 # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
36 # is contrary to our usage. Disable this feature.
37 alias -g '${1+"$@"}'='"$@"'
43 echo "$0: No file. Try \`$0 --help' for more information." 1>&2
48 Usage
: mdate-sh
[--help] [--version] FILE
50 Pretty-print the modification day of FILE
, in the format
:
53 Report bugs to
<bug-automake@gnu.org
>.
58 echo "mdate-sh $scriptversion"
70 # Prevent date giving response in another language.
78 # GNU ls changes its time format in response to the TIME_STYLE
79 # variable. Since we cannot assume `unset' works, revert this
80 # variable to its documented default.
81 if test "${TIME_STYLE+set}" = set; then
82 TIME_STYLE
=posix-long-iso
88 # Find out how to get the extended ls output of a file or directory.
89 if ls -L /dev
/null
1>/dev
/null
2>&1; then
90 ls_command
='ls -L -l -d'
94 # Avoid user/group names that might have spaces, when possible.
95 if ls -n /dev
/null
1>/dev
/null
2>&1; then
96 ls_command
="$ls_command -n"
99 # A `ls -l' line looks as follows on OS/2.
100 # drwxrwx--- 0 Aug 11 2001 foo
101 # This differs from Unix, which adds ownership information.
102 # drwxrwx--- 2 root root 4096 Aug 11 2001 foo
104 # To find the date, we split the line on spaces and iterate on words
105 # until we find a month. This cannot work with files whose owner is a
106 # user named `Jan', or `Feb', etc. However, it's unlikely that `/'
107 # will be owned by a user whose name is a month. So we first look at
108 # the extended ls output of the root directory to decide how many
109 # words should be skipped to get the date.
111 # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
114 # Find which argument is the month.
119 test $# -gt 0 || error
"failed parsing \`$ls_command /' output"
121 # Add another shift to the command.
122 command="$command shift;"
124 Jan
) month
=January
; nummonth
=1;;
125 Feb
) month
=February
; nummonth
=2;;
126 Mar
) month
=March
; nummonth
=3;;
127 Apr
) month
=April
; nummonth
=4;;
128 May
) month
=May
; nummonth
=5;;
129 Jun
) month
=June
; nummonth
=6;;
130 Jul
) month
=July
; nummonth
=7;;
131 Aug
) month
=August
; nummonth
=8;;
132 Sep
) month
=September
; nummonth
=9;;
133 Oct
) month
=October
; nummonth
=10;;
134 Nov
) month
=November
; nummonth
=11;;
135 Dec
) month
=December
; nummonth
=12;;
139 test -n "$month" || error
"failed parsing \`$ls_command /' output"
141 # Get the extended ls output of the file or directory.
142 set dummy x
`eval "$ls_command \"\\\$save_arg1\""`
144 # Remove all preceding arguments
147 # Because of the dummy argument above, month is in $2.
149 # On a POSIX system, we should have
158 # On Darwin 7.7.0 and 7.6.0, we have
168 Jan
) month
=January
; nummonth
=1;;
169 Feb
) month
=February
; nummonth
=2;;
170 Mar
) month
=March
; nummonth
=3;;
171 Apr
) month
=April
; nummonth
=4;;
172 May
) month
=May
; nummonth
=5;;
173 Jun
) month
=June
; nummonth
=6;;
174 Jul
) month
=July
; nummonth
=7;;
175 Aug
) month
=August
; nummonth
=8;;
176 Sep
) month
=September
; nummonth
=9;;
177 Oct
) month
=October
; nummonth
=10;;
178 Nov
) month
=November
; nummonth
=11;;
179 Dec
) month
=December
; nummonth
=12;;
187 # Here we have to deal with the problem that the ls output gives either
188 # the time of day or the year.
190 *:*) set `date`; eval year
=\$
$#
201 Oct
) nummonthtod
=10;;
202 Nov
) nummonthtod
=11;;
203 Dec
) nummonthtod
=12;;
205 # For the first six month of the year the time notation can also
206 # be used for files modified in the last year.
207 if (expr $nummonth \
> $nummonthtod) > /dev
/null
;
209 year
=`expr $year - 1`
215 echo $day $month $year
220 # eval: (add-hook 'write-file-hooks 'time-stamp)
221 # time-stamp-start: "scriptversion="
222 # time-stamp-format: "%:y-%02m-%02d.%02H"
223 # time-stamp-time-zone: "UTC"
224 # time-stamp-end: "; # UTC"