head 1.24; access; symbols SHTOOL_2_0_8:1.24 SHTOOL_2_0_7:1.23 SHTOOL_2_0_6:1.22 SHTOOL_2_0_5:1.22 SHTOOL_2_0_4:1.22 SHTOOL_2_0_3:1.21 SHTOOL_2_0_2:1.21 SHTOOL_2_0_1:1.20 SHTOOL_2_0_0:1.20 SHTOOL_2_0b3:1.20 SHTOOL_2_0b2:1.20 SHTOOL_2_0b1:1.20 SHTOOL_1_6:1.15.0.2 SHTOOL_1_6_2:1.15 SHTOOL_1_6_1:1.15 SHTOOL_1_6_0:1.15 SHTOOL_1_5:1.13.0.2 SHTOOL_1_5_4:1.13 SHTOOL_1_5_3:1.13 SHTOOL_1_5_2:1.13 SHTOOL_1_5_1:1.12 SHTOOL_1_5_0:1.12 SHTOOL_1_4_9:1.12 SHTOOL_1_4_8:1.11 SHTOOL_1_4_7:1.8 SHTOOL_1_4_6:1.8 SHTOOL_1_4_5:1.8 SHTOOL_1_4_4:1.8 SHTOOL_1_4_3:1.8 SHTOOL_1_4_2:1.8 SHTOOL_1_4_1:1.8 SHTOOL_1_4_0:1.8 SHTOOL_1_3_3:1.7 SHTOOL_1_3_2:1.6 SHTOOL_1_3_1:1.5 SHTOOL_1_3_0:1.5 SHTOOL_1_2_9:1.2 SHTOOL_1_2_8:1.2 SHTOOL_1_2_7:1.2 SHTOOL_1_2_6:1.2 SHTOOL_1_2_5:1.2 SHTOOL_1_2_4:1.2 SHTOOL_1_2_3:1.2 SHTOOL_1_2_2:1.1.1.1 SHTOOL_1_2_1:1.1.1.1 SHTOOL_1_2_0:1.1.1.1 SHTOOL_1_1_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.24 date 2008.04.02.20.13.43; author rse; state Exp; branches; next 1.23; commitid eB5Wirx8MdMyDzXs; 1.23 date 2007.05.19.19.09.39; author rse; state Exp; branches; next 1.22; commitid OPUF1UBbllBTwzis; 1.22 date 2006.02.04.09.43.25; author rse; state Exp; branches; next 1.21; commitid oWk7BmnyAitJtfkr; 1.21 date 2005.06.15.08.14.35; author rse; state Exp; branches; next 1.20; 1.20 date 2004.02.12.16.06.27; author rse; state Exp; branches; next 1.19; 1.19 date 2004.01.01.16.54.20; author rse; state Exp; branches; next 1.18; 1.18 date 2003.08.13.14.20.34; author rse; state Exp; branches; next 1.17; 1.17 date 2003.02.11.13.00.50; author rse; state Exp; branches; next 1.16; 1.16 date 2003.02.11.12.56.40; author rse; state Exp; branches; next 1.15; 1.15 date 2001.12.31.15.06.04; author rse; state Exp; branches; next 1.14; 1.14 date 2001.09.23.10.58.10; author rse; state Exp; branches; next 1.13; 1.13 date 2001.01.17.09.55.11; author rse; state Exp; branches; next 1.12; 1.12 date 2000.03.24.15.22.51; author rse; state Exp; branches; next 1.11; 1.11 date 2000.03.12.13.28.24; author rse; state Exp; branches; next 1.10; 1.10 date 2000.03.12.12.46.42; author rse; state Exp; branches; next 1.9; 1.9 date 2000.03.12.11.12.21; author rse; state Exp; branches; next 1.8; 1.8 date 99.07.01.13.47.40; author rse; state Exp; branches; next 1.7; 1.7 date 99.06.29.17.26.43; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.17.07.35.08; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.3; 1.3 date 99.06.12.14.08.49; author rse; state Exp; branches; next 1.2; 1.2 date 99.05.06.12.00.12; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.19.50; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.50; author rse; state Exp; branches; next ; desc @@ 1.24 log @adjust copyright for year 2008 @ text @## ## move -- Move files with simultaneous substitution ## Copyright (c) 1999-2008 Ralf S. Engelschall ## ## This file is part of shtool and free software; you can redistribute ## it and/or modify it under the terms of the GNU General Public ## License as published by the Free Software Foundation; either version ## 2 of the License, or (at your option) any later version. ## ## This file is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## str_tool="move" str_usage="[-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve] " arg_spec="2=" opt_spec="v.t.e.p." opt_alias="v:verbose,t:trace,e:expand,p:preserve" opt_v=no opt_t=no opt_e=no opt_p=no . ./sh.common src="$1" dst="$2" # consistency checks if [ ".$src" = . ] || [ ".$dst" = . ]; then echo "$msgprefix:Error: Invalid arguments" 1>&2 shtool_exit 1 fi if [ ".$src" = ".$dst" ]; then echo "$msgprefix:Error: Source and destination files are the same" 1>&2 shtool_exit 1 fi expsrc="$src" if [ ".$opt_e" = .yes ]; then expsrc="`echo $expsrc`" fi if [ ".$opt_e" = .yes ]; then if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then echo "$msgprefix:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2 shtool_exit 1 fi if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then echo "$msgprefix:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2 shtool_exit 1 fi if [ ".$expsrc" = ".$src" ]; then echo "$msgprefix:Error: Sources not found or no asterisk : $src" 1>&2 shtool_exit 1 fi else if [ ! -r "$src" ]; then echo "$msgprefix:Error: Source not found: $src" 1>&2 shtool_exit 1 fi fi # determine substitution patterns if [ ".$opt_e" = .yes ]; then srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'` dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'` fi # iterate over source(s) for onesrc in $expsrc; do if [ .$opt_e = .yes ]; then onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"` else onedst="$dst" fi errorstatus=0 if [ ".$opt_v" = .yes ]; then echo "$onesrc -> $onedst" fi if [ ".$opt_p" = .yes ]; then if [ -r $onedst ]; then if cmp -s $onesrc $onedst; then if [ ".$opt_t" = .yes ]; then echo "rm -f $onesrc" 1>&2 fi rm -f $onesrc || errorstatus=$? else if [ ".$opt_t" = .yes ]; then echo "mv -f $onesrc $onedst" 1>&2 fi mv -f $onesrc $onedst || errorstatus=$? fi else if [ ".$opt_t" = .yes ]; then echo "mv -f $onesrc $onedst" 1>&2 fi mv -f $onesrc $onedst || errorstatus=$? fi else if [ ".$opt_t" = .yes ]; then echo "mv -f $onesrc $onedst" 1>&2 fi mv -f $onesrc $onedst || errorstatus=$? fi if [ $errorstatus -ne 0 ]; then break; fi done shtool_exit $errorstatus ## ## manual page ## =pod =head1 NAME B - B enhanced mv(1) replacement =head1 SYNOPSIS B [B<-v>|B<--verbose>] [B<-t>|B<--trace>] [B<-e>|B<--expand>] [B<-p>|B<--preserve>] I I =head1 DESCRIPTION This is a mv(1) style command enhanced with the ability to rename multiple files in a single operation and the ability to detect and not touch existing equal destinations files, thus preserving timestamps. =head1 OPTIONS The following command line options are available. =over 4 =item B<-v>, B<--verbose> Display some processing information. =item B<-t>, B<--trace> Enable the output of the essential shell commands which are executed. =item B<-e>, B<--expand> Expand asterisk in I to be used as "C<%>I" (where I is C<1>,C<2>,...) in I. This is useful for renaming multiple files at once. =item B<-p>, B<--preserve> Detect I and I having equal content and not touch existing destination files, thus perserving timestamps. This is useful for applications that monitor timestamps, i.e. suppress make(1L) repeating actions for unchanged files. =back =head1 EXAMPLE # shell script shtool move -v -e '*.txt' %1.asc # Makefile scanner.c: scanner.l lex scanner.l shtool move -t -p lex.yy.c scanner.c =head1 HISTORY The B B command was originally written by Ralf S. Engelschall Erse@@engelschall.comE in 1999 for B. =head1 SEE ALSO shtool(1), mv(1), make(1). =cut @ 1.23 log @Adjust copyright for year 2007. @ text @d3 1 a3 1 ## Copyright (c) 1999-2007 Ralf S. Engelschall @ 1.22 log @Adjust copyright for year 2006 @ text @d3 1 a3 1 ## Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.21 log @Adjust copyright for year 2005 @ text @d3 1 a3 1 ## Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.20 log @Embedded the command documentation from shtool.pod into the individual sh.xxxx scripts and this way split the large shtool(1) manual page into individual manual pages shtool-xxxx(1). Submitted partly by: Thomas Lotterer @ text @d3 1 a3 1 ## Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.19 log @Bump copyright year for 2004 @ text @a3 1 ## Originally written for shtool d115 1 d117 76 @ 1.18 log @Replace "[ x -o/-a x ]" constructs with "[ x ] ||/&& [ x ]" and "egrep"/"fgrep" constructs with compatible "grep" or "case" constructs. This way GNU shtool is now more POSIX 1003.1-2001 compliant. Submitted by: Paul Eggert @ text @d3 1 a3 1 ## Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.17 log @Bump year in copyright messages to cover new year 2003. @ text @d38 1 a38 1 if [ ".$src" = . -o ".$dst" = . ]; then @ 1.16 log @Fixed error exit in all commands by introducing an "shtool_exit" function (which correctly cleans up temporary files) and replacing all "exit" calls with "shtool_exit". THIS THE FIRST TIME INTRODUCED THE USAGE OF A SHELL FUNCTION TO THE SHTOOL CODE. This is known to break on _very_ anchient and broken Bourne-Shell implementations and is considered to be no longer a real problem in the year 2003. Especially there is no alternative way anyway. @ text @d3 1 a3 1 ## Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.15 log @bump copyright years @ text @d40 1 a40 1 exit 1 d44 1 a44 1 exit 1 d53 1 a53 1 exit 1 d57 1 a57 1 exit 1 d61 1 a61 1 exit 1 d66 1 a66 1 exit 1 d116 1 a116 1 exit $errorstatus @ 1.14 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.13 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-v] [-t] [-e] [-p] " d26 1 @ 1.12 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.11 log @*** empty log message *** @ text @d2 1 a2 1 ## move -- Move files with simultan substitution @ 1.10 log @*** empty log message *** @ text @d25 5 a29 1 opt_spec="vtep" @ 1.9 log @*** empty log message *** @ text @d24 1 a24 1 arg_spec="2" @ 1.8 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1999 Ralf S. Engelschall @ 1.7 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-e] [-p] " d25 1 a25 1 opt_spec="ep" d79 3 d85 3 d90 3 d96 3 d102 4 a105 1 mv -f $onesrc $onedst || errorstatus=$? @ 1.6 log @*** empty log message *** @ text @d82 1 a82 1 rm -f $onesrc || errstatus=$? d84 1 a84 1 mv -f $onesrc $onedst || errstatus=$? d87 1 a87 1 mv -f $onesrc $onedst || errstatus=$? d90 1 a90 1 mv -f $onesrc $onedst || errstatus=$? @ 1.5 log @*** empty log message *** @ text @d27 1 a27 1 . sh.common @ 1.4 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-e] [-p] " @ 1.3 log @*** empty log message *** @ text @d2 2 a3 2 ## move -- Move files with simultan substitution and optimized movement ## Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. d5 15 @ 1.2 log @*** empty log message *** @ text @a0 1 #!/bin/sh d4 1 a4 1 ## Usage: move [-e] [-p] d7 9 a15 18 # # command line parsing # expand=no preserve=no while [ ".$1" != . ]; do case $1 in -e ) expand=yes ; shift; continue ;; -p ) preserve=yes ; shift; continue ;; * ) break ;; esac done if [ $# -ne 2 ]; then echo "$0:Usage: move [-e] [-p] " 1>&2 exit 1 fi src=$1 dst=$2 a16 1 # a17 1 # d19 1 a19 1 echo "$0:Error: Invalid arguments" 1>&2 d23 1 a23 1 echo "$0:Error: Source and destination files are the same" 1>&2 d27 1 a27 1 if [ $expand = yes ]; then d30 1 a30 1 if [ $expand = yes ]; then d32 1 a32 1 echo "$0:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2 d36 1 a36 1 echo "$0:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2 d40 1 a40 1 echo "$0:Error: Sources not found or no asterisk : $src" 1>&2 d45 1 a45 1 echo "$0:Error: Source not found: $src" 1>&2 a49 1 # d51 1 a51 2 # if [ $expand = yes ]; then a55 1 # a56 1 # d58 1 a58 1 if [ $expand = yes ]; then d64 7 a70 3 if [ -r $onedst ]; then if cmp -s $onesrc $onedst; then rm -f $onesrc || errstatus=$? d75 1 a75 1 mv -f $onesrc $onedst || errstatus=$? a80 2 # die gracefully @ 1.1 log @Initial revision @ text @d3 1 a3 1 ## move -- Move files, but if files are the same just delete the source d5 1 a5 1 ## Usage: move d9 1 a9 1 # command line d11 9 d21 1 a21 1 echo "$0:Error: Invalid number of arguments" 1>&2 d26 4 d34 1 a34 1 if [ $src = $dst ]; then d38 30 a67 3 if [ ! -r $src ]; then echo "$0:Error: Source not found: $src" 1>&2 exit 1 d71 1 a71 1 # perform the optimized move d73 3 a75 4 errorstatus=0 if [ -r $dst ]; then if cmp -s $src $dst; then rm -f $src || errstatus=$? d77 1 a77 1 mv -f $src $dst || errstatus=$? d79 14 a92 3 else mv -f $src $dst || errstatus=$? fi @ 1.1.1.1 log @Import of shtool 1.1.0 @ text @@