*BSD News Article 42652


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!constellation!news.ysu.edu!usenet.ins.cwru.edu!howland.reston.ans.net!news.moneng.mei.com!hookup!solaris.cc.vt.edu!kaleka.seanet.com!news.seanet.com!michaelv
From: michaelv@MindBender.HeadCandy.com (Michael L. VanLoon)
Newsgroups: comp.unix.bsd
Subject: Re: Newbie Question: mv *.t *.txt ????
Date: 19 Feb 1995 21:49:50 GMT
Organization: HeadCandy Associates... Sweets for the lobes.
Lines: 42
Message-ID: <MICHAELV.95Feb19134950@MindBender.HeadCandy.com>
References: <D41nyo.Mon@ritz.mordor.com> <3huiti$4lr@dagny.galt.com>
	<3i841g$48b@csugrad.cs.vt.edu>
NNTP-Posting-Host: mindbender.seanet.com
In-reply-to: jaitken@csugrad.cs.vt.edu's message of 19 Feb 1995 13:52:32 -0500

   : Hany Nagib (hany@ritz.mordor.com) wrote:
   : : I know this must be a very simple question, but it's not in the FAQ.
   : : "mv" looks like it works exactly like "rename" in DOS, except when using 
   : : wild card. For example if I wanted to rename all my .t files to .txt, I 
   : : expect "mv *.t *.txt" to work .. but it doesn't. Why ? And how do I 
   : : accomplish this in BSD unix ?

You need to get a unix shell FAQ and read it.  I believe there's one
posted regularly in comp.unix.shell (or comp.unix.shells... whatever).

The reason it doesn't work is because the shell expands the "wildcard"
characters *before* it does anything else, unlike the brain-dead DOS
shell which just passes them to the program, and each program has to
invent its own code to parse them.

So, in this example, before it even executes the mv command, it tries
to expand "*.t *.txt".  You don't have any files (assuming in this
case) which end with *.txt, so that expands to nothing.  Assuming you
had files named 1.t 2.t and 3.t, this would then expand to the
following command:

	mv 1.t 2.t 3.t

which, of course, is not at all what you intended.  Or, if in addition
to the .t files, you had maybe "readme.txt" in that dir, you'd get
this:

	mv 1.t 2.t 3.t readme.txt

The key here is to understand how unix shells work.  Once you get the
hang of it, it all makes perfect sense.

Read the FAQ.  And, if you really want to get good at this, buy a unix
shell book.

--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Michael L. VanLoon  michaelv@HeadCandy.com  michaelv@MindBender.seanet.com
  Free your mind and your machine -- NetBSD free un*x for PC/Mac/Amiga/etc.
     Working NetBSD ports: 386+PC, Mac, Amiga, HP300, Sun3, Sun4c, PC532
               In progress: DEC pmax (MIPS R2k/3k), VAX, Sun4m
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -