1*38fd1498Szrj#!/bin/sh 2*38fd1498Szrj# Like mv $1 $2, but if the files are the same, just delete $1. 3*38fd1498Szrj# Status is zero if successful, nonzero otherwise. 4*38fd1498Szrj 5*38fd1498SzrjVERSION='2012-01-06 07:23'; # UTC 6*38fd1498Szrj# The definition above must lie within the first 8 lines in order 7*38fd1498Szrj# for the Emacs time-stamp write hook (at end) to update it. 8*38fd1498Szrj# If you change this file with Emacs, please let the write hook 9*38fd1498Szrj# do its job. Otherwise, update this string manually. 10*38fd1498Szrj 11*38fd1498Szrj# Copyright (C) 2002-2014 Free Software Foundation, Inc. 12*38fd1498Szrj 13*38fd1498Szrj# This program is free software: you can redistribute it and/or modify 14*38fd1498Szrj# it under the terms of the GNU General Public License as published by 15*38fd1498Szrj# the Free Software Foundation, either version 3 of the License, or 16*38fd1498Szrj# (at your option) any later version. 17*38fd1498Szrj 18*38fd1498Szrj# This program is distributed in the hope that it will be useful, 19*38fd1498Szrj# but WITHOUT ANY WARRANTY; without even the implied warranty of 20*38fd1498Szrj# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*38fd1498Szrj# GNU General Public License for more details. 22*38fd1498Szrj 23*38fd1498Szrj# You should have received a copy of the GNU General Public License 24*38fd1498Szrj# along with this program. If not, see <http://www.gnu.org/licenses/>. 25*38fd1498Szrj 26*38fd1498Szrjusage="usage: $0 SOURCE DEST" 27*38fd1498Szrj 28*38fd1498Szrjhelp="$usage 29*38fd1498Szrj or: $0 OPTION 30*38fd1498SzrjIf SOURCE is different than DEST, then move it to DEST; else remove SOURCE. 31*38fd1498Szrj 32*38fd1498Szrj --help display this help and exit 33*38fd1498Szrj --version output version information and exit 34*38fd1498Szrj 35*38fd1498SzrjThe variable CMPPROG can be used to specify an alternative to 'cmp'. 36*38fd1498Szrj 37*38fd1498SzrjReport bugs to <bug-gnulib@gnu.org>." 38*38fd1498Szrj 39*38fd1498Szrjversion=`expr "$VERSION" : '\([^ ]*\)'` 40*38fd1498Szrjversion="move-if-change (gnulib) $version 41*38fd1498SzrjCopyright (C) 2011 Free Software Foundation, Inc. 42*38fd1498SzrjLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 43*38fd1498SzrjThis is free software: you are free to change and redistribute it. 44*38fd1498SzrjThere is NO WARRANTY, to the extent permitted by law." 45*38fd1498Szrj 46*38fd1498Szrjcmpprog=${CMPPROG-cmp} 47*38fd1498Szrj 48*38fd1498Szrjfor arg 49*38fd1498Szrjdo 50*38fd1498Szrj case $arg in 51*38fd1498Szrj --help | --hel | --he | --h) 52*38fd1498Szrj exec echo "$help" ;; 53*38fd1498Szrj --version | --versio | --versi | --vers | --ver | --ve | --v) 54*38fd1498Szrj exec echo "$version" ;; 55*38fd1498Szrj --) 56*38fd1498Szrj shift 57*38fd1498Szrj break ;; 58*38fd1498Szrj -*) 59*38fd1498Szrj echo "$0: invalid option: $arg" >&2 60*38fd1498Szrj exit 1 ;; 61*38fd1498Szrj *) 62*38fd1498Szrj break ;; 63*38fd1498Szrj esac 64*38fd1498Szrjdone 65*38fd1498Szrj 66*38fd1498Szrjtest $# -eq 2 || { echo "$0: $usage" >&2; exit 1; } 67*38fd1498Szrj 68*38fd1498Szrjif test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null; then 69*38fd1498Szrj rm -f -- "$1" 70*38fd1498Szrjelse 71*38fd1498Szrj if mv -f -- "$1" "$2"; then :; else 72*38fd1498Szrj # Ignore failure due to a concurrent move-if-change. 73*38fd1498Szrj test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null && rm -f -- "$1" 74*38fd1498Szrj fi 75*38fd1498Szrjfi 76*38fd1498Szrj 77*38fd1498Szrj## Local Variables: 78*38fd1498Szrj## eval: (add-hook 'write-file-hooks 'time-stamp) 79*38fd1498Szrj## time-stamp-start: "VERSION='" 80*38fd1498Szrj## time-stamp-format: "%:y-%02m-%02d %02H:%02M" 81*38fd1498Szrj## time-stamp-time-zone: "UTC" 82*38fd1498Szrj## time-stamp-end: "'; # UTC" 83*38fd1498Szrj## End: 84