LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-13-2010, 05:22 PM   #1
poorboyiii
LQ Newbie
 
Registered: Feb 2007
Location: Joliet/Plainfield Illinois
Distribution: Ubuntu
Posts: 19

Rep: Reputation: 0
Smile Shell script question


If someone could help with a simple shell program it would be greatly appreciated.

I have a directory with several files in it each having an extension of ".JPG" and need to change the extension to lower case ".jpg".
I wrote the following:
--------------------------
#!/bin/bash

for ofn in *.JPG
do
cnt=${#ofn}-3
nfn=${ofn:0:cnt}"jpg"
echo $ofn $nfn #not necessary but shows the value of the two names
mv -v $ofn $nfn
done
--------------------------

The directory contains the shell program and the following:
0614 Kite.JPG
0615 Kite.JPG
0616 Kite.JPG
0617 Kite.JPG
0618 Kite.JPG
0619 Kite.JPG
0620 bushes.JPG
0621 plants.JPG

The output is:
0614 Kite.JPG 0614 Kite.jpg
mv: target `Kite.jpg' is not a directory
0615 Kite.JPG 0615 Kite.jpg
mv: target `Kite.jpg' is not a directory
0616 Kite.JPG 0616 Kite.jpg
mv: target `Kite.jpg' is not a directory
0617 Kite.JPG 0617 Kite.jpg
mv: target `Kite.jpg' is not a directory
0618 Kite.JPG 0618 Kite.jpg
mv: target `Kite.jpg' is not a directory
0619 Kite.JPG 0619 Kite.jpg
mv: target `Kite.jpg' is not a directory
0620 bushes.JPG 0620 bushes.jpg
mv: target `bushes.jpg' is not a directory
0621 plants.JPG 0621 plants.jpg
mv: target `plants.jpg' is not a directory


Thanks Sam
 
Old 02-13-2010, 05:31 PM   #2
jhcaiced
Member
 
Registered: Mar 2009
Distribution: CentOS - Ubuntu - Debian
Posts: 83

Rep: Reputation: 27
Hi,

The problem seems to be the spaces in your file names, add quotes to the mv command to avoid this.

mv -v "$ofn" "$nfn"

Best regards,
 
0 members found this post helpful.
Old 02-13-2010, 05:41 PM   #3
poorboyiii
LQ Newbie
 
Registered: Feb 2007
Location: Joliet/Plainfield Illinois
Distribution: Ubuntu
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jhcaiced View Post
Hi,

The problem seems to be the spaces in your file names, add quotes to the mv command to avoid this.

mv -v "$ofn" "$nfn"

Best regards,
That worked Thanks.....

Sam
 
Old 02-13-2010, 05:42 PM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Take a look at the rename command.
Code:
rename .JPG .jpg *.JPG
 
  


Reply

Tags
scripting, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script question psynce_friction Programming 10 11-21-2009 04:26 AM
Shell Script Question dennismonsewicz Linux - Newbie 3 04-27-2009 01:27 PM
Shell Script Question. rvijay Linux - General 2 07-14-2005 06:41 PM
shell script question yoderp Programming 6 06-16-2005 04:47 PM
Shell script question paraiso Linux - Newbie 2 05-15-2005 01:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration