autoconf-patches
[Top][All Lists]
Advanced

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

Re: Quieten move-if-change?


From: Paul Eggert
Subject: Re: Quieten move-if-change?
Date: Tue, 06 Sep 2005 13:00:48 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Ben Elliston <address@hidden> writes:

> move-if-change currently outputs "<file> is unchanged" when it does
> nothing.  This adds undue noise in GCC builds.  Would it be possible
> to give it more natural behaviour like mv(1) and output nothing,
> regardless of whether it moves the file?

Sure.  While we're at it, let's make it safe in the presence of
unusual characters, and fix the bogus comment about the exit status.
(How many bugs can there be in a 10-line shell script?  Sheesh.)
I installed this:

2005-09-06  Paul Eggert  <address@hidden>

        * config/move-if-change: Don't output "$2 is unchanged";
        suggested by Ben Elliston.  Handle weird characters correctly.

--- config/move-if-change       15 Nov 2002 09:17:30 -0000      1.2
+++ config/move-if-change       6 Sep 2005 19:59:08 -0000
@@ -1,13 +1,22 @@
 #!/bin/sh
 # Like mv $1 $2, but if the files are the same, just delete $1.
-# Status is 0 if $2 is changed, 1 otherwise.
-if test -r $2; then
-  if cmp -s $1 $2; then
-    echo $2 is unchanged
-    rm -f $1
-  else
-    mv -f $1 $2
-  fi
+# Status is zero if successful, nonzero otherwise.
+
+usage="$0: usage: $0 SOURCE DEST"
+
+case $# in
+2) ;;
+*) echo "$usage" >&2; exit 1;;
+esac
+
+for arg in "$1" "$2"; do
+  case $arg in
+   -*) echo "$usage" >&2; exit 1;;
+  esac
+done
+
+if test -r "$2" && cmp -s "$1" "$2"; then
+  rm -f "$1"
 else
-  mv -f $1 $2
+  mv -f "$1" "$2"
 fi




reply via email to

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