Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-16-2006, 01:39 AM
|
#1
|
Member
Registered: Dec 2004
Location: Haifa
Distribution: Fedora Core 4, Kubuntu
Posts: 235
Rep:
|
spaces in filenames
Another LinuxQuestions user has provided me with a simple bash script that performs an operation on all the files of a directory. However, many of the file names contain spaces. How can I modify the following code to work on files with spaces? The directory is on a mounted FAT32 partition.
Code:
#!/bin/bash
PWD=`pwd`
for file in `find $PWD -name "*.mp3"`
do
eyeD3 --force-update --set-encoding=utf8 $file
done
I had considered converting the spaces to underscores, but that would upset the delicate wife/linux balance in our household.
Thank you.
|
|
|
02-16-2006, 02:41 AM
|
#2
|
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109
Rep:
|
Hi.
Replace $file with "$file"
Dave
|
|
|
02-16-2006, 02:44 AM
|
#3
|
Member
Registered: Dec 2004
Location: Haifa
Distribution: Fedora Core 4, Kubuntu
Posts: 235
Original Poster
Rep:
|
Thank you!
|
|
|
02-16-2006, 02:51 AM
|
#4
|
Senior Member
Registered: Aug 2005
Posts: 1,755
Rep:
|
Quote:
Originally Posted by dotancohen
Code:
#!/bin/bash
PWD=`pwd`
for file in `find $PWD -name "*.mp3"`
do
eyeD3 --force-update --set-encoding=utf8 "$file"
done
|
You could also do this with something like
Code:
find . -name "*.mp3" -exec eyeD3 --force-update --set-encoding=utf8 '{}' \;
|
|
|
02-16-2006, 03:07 AM
|
#5
|
Member
Registered: Dec 2004
Location: Haifa
Distribution: Fedora Core 4, Kubuntu
Posts: 235
Original Poster
Rep:
|
Er, didn't quite work. It still returns "file not found" for each file with spaces in the name.
In your second suggestion, is this the script that you suggest?:
Code:
#!/bin/bash
find . -name "*.mp3" -exec eyeD3 --force-update --set-encoding=utf8 '{}' \;
done
I just want to be sure before I ruin something.
|
|
|
02-16-2006, 03:54 AM
|
#6
|
Senior Member
Registered: Aug 2005
Posts: 1,755
Rep:
|
Yes, or just run it on the command line.
Hmm, perhaps the quoting the filename thing will work here:
Code:
find . -name "*.mp3" -exec eyeD3 --force-update --set-encoding=utf8 "'{}'" \;
|
|
|
02-16-2006, 04:30 AM
|
#7
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
You shouldn't need all those quotes for find -exec, just the {}
should do it. It works OK for me with spaces.
FYI
PWD=`pwd`??? this is pointless. PWD is already set.
|
|
|
02-16-2006, 05:52 AM
|
#8
|
Member
Registered: Dec 2004
Location: Haifa
Distribution: Fedora Core 4, Kubuntu
Posts: 235
Original Poster
Rep:
|
Thanks. As bigearsbilly had mentioned, the quotation marks around {} were redundant. It now works!
1) there was plenty of disk space
2) permissions were never a problem
Thank you.
Last edited by dotancohen; 02-16-2006 at 05:56 AM.
|
|
|
02-16-2006, 05:54 AM
|
#9
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
1) 2)
no that's just my signature 
|
|
|
02-16-2006, 07:41 AM
|
#10
|
Member
Registered: Sep 2005
Posts: 145
Rep:
|
please post the result of this:
#!/bin/bash
for i in 'find --name "*.txt"'
do
echo $i
done
Just to text wat's the output of $i in ur box.
|
|
|
02-16-2006, 07:54 AM
|
#11
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Rep:
|
Code:
find --name "*.txt"
this would result in error in any shell
|
|
|
02-16-2006, 07:59 AM
|
#12
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
if no subdirectories
Code:
for f in *.txt ;do
echo $f
done
|
|
|
02-17-2006, 02:42 PM
|
#13
|
Member
Registered: Dec 2004
Location: Haifa
Distribution: Fedora Core 4, Kubuntu
Posts: 235
Original Poster
Rep:
|
In any case, I got it working with the code that spooon had suggested.
|
|
|
All times are GMT -5. The time now is 08:57 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|