[Top][All Lists]

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

Re: [gNewSense-users] Strange find behavior

From: Matthew Flaschen
Subject: Re: [gNewSense-users] Strange find behavior
Date: Sat, 31 Mar 2007 04:20:20 -0400
User-agent: Thunderbird (X11/20070306)

Chris F.A. Johnson wrote:
> 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.

I'll still have to copy it everywhere, since it isn't standard.

>>  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.

Yes.  I know both of them now.  If neither work, I'll fall back on the

>> 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

Thanks.  That '%' syntax will take getting used to, though.

Matt Flaschen

reply via email to

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