On Tue, 12 Feb 2002, Cameron Simpson wrote:

> Date: Tue, 12 Feb 2002 15:51:10 +1100
> From: Cameron Simpson <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: Re: Change file extension using bash (OT)
> 
> On 23:39 11 Feb 2002, Reuben D Budiardja <[EMAIL PROTECTED]> wrote:
> | I need a bit of help with bash here. I try to create a script that would 
> | change the extension of files in directory. I have files like 
> | xxx.pc that I want a change to xxx.jpg, where xxx is numbers, in a directory. 
> | How can I do that using bash?
> 
> for f in *.pc
> do  newname=`basename "$f" .bc`.jpg
>     mv -i "$f" "$newname"
> done
It seems that you try to work correctly for file names containing spaces,
etc; if so, the results of basename should be protected
from word split (I am also correcting mistyped ".bc")

for f in *.pc; do newname="`basename "$f" .pc`".jpg;
mv -i "$f" "$newname"; done
> 
> Of course that works in any Bourne shell, not just bash. Which is as it should be.
> -- 
> Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/
> 

If we want bash-only solution we can use a bit faster (no subprocessed
created):

for f in *.pc; do newname="${f%.pc}".jpg; mv -i "$f" "$newname"; done

Best regards,

Wojtek




_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to