LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-17-2012, 11:07 AM   #16
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,839

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006

Quote:
Originally Posted by shayno90 View Post
Attempted it without sudo and it seemed to work:

mv: cannot `windows-system-characteristics-schema.xsd' change to `windows-system-characteristics-schema.oval': Permission denied
mv: cannot `xmldsig-core-schema.xsd' change to `xmldsig-core-schema.oval': Permission denied

but after sudoing got this then:

user@user:/usr/local/share/ovaldi/xmltest$ sudo for i in *.xsd; do mv "$i" "${i/.xsd/.oval}"; done
bash: Syntax error beside "do" cannot continue with it.

What is the issue with 'do'?
do is the opening of the for loop. What I wrote is actually a 4 line script rolled into one line using semicolons, ie:
Code:
for i in *.xsd
do
   mv "$i" "${i/.xsd/.oval}"
done
Chances are the sudo is what's messing things up, since it's "sudoing" the for, and not the rest. I never use sudo, so I can't really test it, but this might be the change you need:

Code:
for i in *.xsd; do sudo mv "$i" "${i/.xsd/.oval}"; done
 
1 members found this post helpful.
Old 03-01-2012, 06:35 PM   #17
shayno90
Member
 
Registered: Oct 2009
Distribution: Debian Lenny 2.6.26 Ubuntu Lucid Lynx 10.04 Windows 7
Posts: 187
Blog Entries: 2

Original Poster
Rep: Reputation: 21
Code:
for i in *.xsd; do sudo mv "$i" "${i/.xsd/.oval}"; done
Thanks for the input on this suicidaleggroll!

Last edited by shayno90; 03-01-2012 at 06:37 PM.
 
Old 03-02-2012, 08:39 AM   #18
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,431
Blog Entries: 33

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Quote:
Originally Posted by suicidaleggroll View Post
Yes it will, the quotes cover that. I use it all the time.
No it won't. Do an example yourself and see.

Code:
touch old\ file.old
touch old-file.old
for i in *.old; do mv "$i" "${i/.old/.new}"; done
You will get "old not found" and "file.old not found" errors when you run that for loop. Unless you've changed your field separator in the IFS variable to see newlines as the field separator that for loop does not work on file names with spaces. The for loop separates arguments based on spaces. That's why I gave you the while read line loop.

Last edited by sag47; 03-02-2012 at 08:41 AM.
 
Old 03-02-2012, 09:42 AM   #19
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,839

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
Quote:
Originally Posted by sag47 View Post
No it won't. Do an example yourself and see.

Code:
touch old\ file.old
touch old-file.old
for i in *.old; do mv "$i" "${i/.old/.new}"; done
You will get "old not found" and "file.old not found" errors when you run that for loop. Unless you've changed your field separator in the IFS variable to see newlines as the field separator that for loop does not work on file names with spaces. The for loop separates arguments based on spaces. That's why I gave you the while read line loop.
RHEL:
Code:
[eggroll@picard test]$ touch old\ file.old
[eggroll@picard test]$ touch old-file.old
[eggroll@picard test]$ for i in *.old; do mv "$i" "${i/.old/.new}"; done
[eggroll@picard test]$ ls
old file.new  old-file.new
I have also tested it successfully on CentOS, Fedora, Mint, OpenSUSE, Cygwin, and BusyBox. None of them have modified IFS. I just set up the Mint box not 24 hours ago, haven't modified anything on it really, and it works fine. If I had access to more distros, I would try them as well, but so far I haven't found a single distro that it doesn't work on, including the limited ones used on embedded systems like the GESBC-9260S and Gumstix.

You would be right if I had written it like:
Code:
for i in $(ls *.old); do mv "$i" "${i/.old/.new}"; done
but that's why I didn't write it like that. "for i in *.old" does not work the same way as "for i in $(ls *.old)", and does not suffer from the problem you're describing, at least not on any system I've ever used.

Last edited by suicidaleggroll; 03-02-2012 at 10:27 AM.
 
Old 03-02-2012, 01:14 PM   #20
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,431
Blog Entries: 33

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Quote:
Originally Posted by suicidaleggroll View Post
You would be right if I had written it like:
Code:
for i in $(ls *.old); do mv "$i" "${i/.old/.new}"; done
but that's why I didn't write it like that. "for i in *.old" does not work the same way as "for i in $(ls *.old)", and does not suffer from the problem you're describing, at least not on any system I've ever used.
Ah I had it confused with the ls command as I've tried that in the past. My bad.
 
  


Reply

Tags
bash scripting, directory, extension, file, replace


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert multiple file in directory: ascii to hex in perl fad216 Programming 3 04-10-2011 12:47 PM
Bash script to copy specified extension file from a directory? sokha Programming 11 03-15-2010 02:51 AM
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 04:19 PM
batch file to convert every file in a directory with mencoder. toben Linux - Software 1 01-31-2008 05:28 PM
file to convert from pictClipping extension to jpeg - macutils dumpthecore Linux - Newbie 0 11-12-2003 01:07 AM


All times are GMT -5. The time now is 03:37 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration