simple question about mv

Jon H. LaBadie jon at jonlab.UUCP
Wed Feb 1 13:23:51 AEST 1989


In article <4093 at omepd.UUCP>, merlyn at intelob.intel.com (Randal L. Schwartz @ Stonehenge) writes:
In article <18231 at adm.BRL.MIL>, moss at BRL (VLD/VMB) writes:
| Well, this should work under a Bourne shell:
| $ for i in *.flip
| > do	mv $i `basename $i .flip` .flop
| > done
| $

Randal and others (this is not intended to pick on Randal's suggestion)
have proposed work-arounds to UNIX's command line interpreters (or to
mv's) deficiency in wild card matching.  Each have proposed a separate
mv command for each file.  This is unfortunate, but probably necessary.

However, each suggestion has also necessitated a separate process such
as cut, sed, or in Randal's case, basename, for each file to be moved.
An alternative, is one command line to create a list of "root names"
and loop through them.  For a large number of files, this could
greatly enhance the efficiency of the processing.  Ksh users could
improve upon this even more using the special substitution facilities
of that shell.

	for root in `ls *.flip | cut -d. -f1`
	do
		mv ${root}.flip ${root}.flop
	done

Potential problems still exist if a) two "."s are int the file names,
or b) not ".flip" files exist.

Isn't UNIX great?  :-)  for guru's!  ;-)
-- 
Jon LaBadie
{att, ulysses, princeton, bcr}!jonlab!jon



More information about the Comp.unix.questions mailing list