Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* copy *.doc *.bak (Was: Re: The big Question)
  1995-01-04 16:04             ` Jim_Mann
@ 1995-01-05  0:01               ` Rick
  0 siblings, 0 replies; 2+ messages in thread
From: Rick @ 1995-01-05  0:01 UTC (permalink / raw)


Jim_Mann@transarc.com writes:

>On the other hand, because of this, I believe DOS will allow you to
>issue a command like: 

>   copy *.doc *.bak

>and have it do the right thing (copy a.doc to a.bak, b.doc to b.bak,
>and so forth). Because the shell handles expansion in UNIX, UNIX
>can't do this sort of thing.

Depends on your shell.  zsh allows you to turn off globbing for
selected commands.  As an example, here's a Q&D rendition of the DOS
rename command from my .zprofile:

	rename () {
		[ $# != 2 ] && {
			echo "usage: ren pat1 pat2"
			return 1
		}
		srcpat=$(echo $1 | sed -e 's/\*/\\(.*\\)/')
		dstpat=$(echo $2 | sed -e 's/\*/\\1/')
		for i in `eval echo $1` ; do
			mv -i $i $(echo $i|sed -e "s/$srcpat/$dstpat/") || break
		done
	}
	alias ren="noglob rename"

It only matches the first wildcard, doesn't handle `?', but it'll do
"ren *.c *.c.old", and you can specify a path in the destination
(ren *.doc backup/*.bak).

Rick.
-- 
Rick "JT" Lyons   | The above bytes don't | Usenet before net uses you.
Telecom Australia | represent the views or| C/C++/x86/X/Unix/DOS/Novell
ACN 051 775 556   | opinions of Telstra.  | Dyslexics of the world untie!
work:pclink@qus102.qld.npb.telecom.com.au | play:rick@razorback.brisnet.org.au


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: copy *.doc *.bak (Was: Re: The big Question)
@ 1995-01-05 20:36 Sara E Rouner
  0 siblings, 0 replies; 2+ messages in thread
From: Sara E Rouner @ 1995-01-05 20:36 UTC (permalink / raw)


>>On the other hand, because of this, I believe DOS will allow you to
>>issue a command like: 

>>>copy *.doc *.bak

>>and have it do the right thing (copy a.doc to a.bak, b.doc to b.bak,
>>and so forth). Because the shell handles expansion in UNIX, UNIX
>>can't do this sort of thing.

I recognize this thread for what it is.. pure flame bait.. but I can't
sit on my hands and let an incorrect statement like this go by
unattended.  Expansion is a major strength of sh-programming.. and so
is parameter execution.  You really need to know that sort of stuff to
get the most from UNIX.

A UNIX user will opt to use a sh-command line like:

   for f in *.doc; do cp $f `basename $f .doc`.bak; done

or, if the list of files is small enough, a sh-command line like:

   for f in a b and so forth; do cp $f.doc $f.bak; done



Do you need a script for your UNIX account?  Is that what you're
really asking for?  Well, this one should work:

#!/bin/sh
## cpx: copies a set of files with the same ext. to a different ext.
## example: to copy all *.doc files to *.bak -- cpx doc bak
for f in *.$1; do cp $f `basename $f .$1`.$2; done


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-01-05 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-01-05 20:36 copy *.doc *.bak (Was: Re: The big Question) Sara E Rouner
  -- strict thread matches above, loose matches on Subject: below --
1994-12-27 18:34 The big Question John Laing Page
1994-12-29 16:50 ` Lee Sailer
1994-12-29  8:12   ` Darko Volaric
1994-12-29 22:27     ` Bob Hetzel
1994-12-31 16:10       ` cdlevin
1995-01-02 13:55         ` Steven Buytaert
1995-01-04  5:16           ` Ross Morley
1995-01-04 16:04             ` Jim_Mann
1995-01-05  0:01               ` copy *.doc *.bak (Was: Re: The big Question) Rick

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox