gnewsense-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gNewSense-users] Strange find behavior


From: Chris F.A. Johnson
Subject: Re: [gNewSense-users] Strange find behavior
Date: Fri, 30 Mar 2007 13:25:19 -0400 (EDT)

On Fri, 30 Mar 2007, Matthew Flaschen wrote:

Chris F.A. Johnson wrote:
   The basename command is executed and the result is placed  on the
   command line. What you are running is:

find -name "*.c" -exec echo {} \;

Thank you.  I should have figured that out.

   Why don't you want to use a script? That's the logical way to do it.

If I made a full-out script myself, I'll have to remake it everywhere I
go.

   Why? Write one script that works everywhere.

 However, I figured out how to work 'rename' (man rename), which is
apparently a simple Perl script designed for this.

   There are at least two different versions of rename. They use
   different syntax, so what you use in one place might not work in
   another.

   I have heard that the perl version is unreliable.

 It won't be everywhere, but it's worth knowing.

Everywhere else, I'll use:

for f in $(ls *.cpp); do mv $f $(basename $f .cpp).c ; done

Not too hard.

   But wrong. It will fail if any filenames contain spaces or other
   pathological characters, partly because of the unnecessary ls, and
   because you didn't quote the variables. It's probably not an issue
   in this case, but it could bite you when you use the same script
   in slightly different circumstances.

   Also, you don't need basename; it's an external command (i.e.,
   slow) which the shell replaces with built-in parameter expansion.

for f in *.cpp
do
   mv "$f" "${f%.cpp}.c"
done

--
   Chris F.A. Johnson                      <http://cfaj.freeshell.org>
   ========= Do not reply to the From: address; use Reply-To: ========
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]