autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mdate-sh


From: Andreas Buening
Subject: Re: mdate-sh
Date: Mon, 06 Jan 2003 12:32:13 +0100

Paul Eggert wrote:
> 
> > Date: Mon, 23 Dec 2002 14:23:08 +0100
> > From: Andreas Buening <address@hidden>
> 
> > +# Get the extended ls output of the root directory.
> > +set - x`eval $ls_command /`
> 
> The "eval " shouldn't be needed here, so it's better to remove it.
> 
> > +# Get the extended ls output of the file or directory.
> > +set - x`eval $ls_command "\"$save_arg1\""`
> 
> Better would be
> 
> set - x`eval "$ls_command \"\$save_arg1\""`
> 
> as this will handle arguments that contain metacharacters like space
> or '"'.

Thanks.

------------------------------------
--- old/mdate-sh        Tue Jul 17 06:00:36 2001
+++ new/mdate-sh        Mon Jan  6 12:05:14 2003
@@ -30,24 +30,27 @@
 LC_TIME=C
 export LC_TIME
 
-# Get the extended ls output of the file or directory.
+save_arg1="$1"
+
+# Find out how to get the extended ls output of a file or directory.
 # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
 if ls -L /dev/null 1>/dev/null 2>&1; then
-  set - x`ls -L -l -d $1`
+  ls_command='ls -L -l -d'
 else
-  set - x`ls -l -d $1`
+  ls_command='ls -l -d'
 fi
-# The month is at least the fourth argument
-# (3 shifts here, the next inside the loop).
-shift
-shift
-shift
 
-# Find the month.  Next argument is day, followed by the year or time.
+# Get the extended ls output of the root directory.
+set - x`$ls_command /`
+
+# Find which argument is the month.
 month=
+command=
 until test $month
 do
   shift
+  # Add another shift to the command.
+  command="$command shift;"
   case $1 in
     Jan) month=January; nummonth=1;;
     Feb) month=February; nummonth=2;;
@@ -63,6 +66,28 @@
     Dec) month=December; nummonth=12;;
   esac
 done
+
+# Get the extended ls output of the file or directory.
+set - x`eval "$ls_command \"\$save_arg1\""`
+
+# Remove all preceding arguments
+eval $command
+
+# Get the month.  Next argument is day, followed by the year or time.
+case $1 in
+  Jan) month=January; nummonth=1;;
+  Feb) month=February; nummonth=2;;
+  Mar) month=March; nummonth=3;;
+  Apr) month=April; nummonth=4;;
+  May) month=May; nummonth=5;;
+  Jun) month=June; nummonth=6;;
+  Jul) month=July; nummonth=7;;
+  Aug) month=August; nummonth=8;;
+  Sep) month=September; nummonth=9;;
+  Oct) month=October; nummonth=10;;
+  Nov) month=November; nummonth=11;;
+  Dec) month=December; nummonth=12;;
+esac
 
 day=$2
 
------------------------------------


> Also, when you resubmit the patch, can you please submit a proper
> ChangeLog entry?  See the ChangeLog file for examples.  Thanks.

Sure. Unfortunately, I tend to forget this part. ;-)

ChangeLog:
2003-01-06  Andreas Buening  <address@hidden>

        * lib/mdate-sh: Find out which column of the ls -l output contains
        the month. Do not assume it is at least the fifth column.


Bye,
Andreas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]