Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-25-2008, 10:10 AM   #1
Registered: Mar 2004
Location: Us
Distribution: Ubuntu Dapper
Posts: 74

Rep: Reputation: 15
bash script to sort mp3 bitrates above and below 128k

I posted a question to yesterday about how one would go about authoring a script to sort several gigs of mp3's into two top level directories (better128) (less128) while preserving current parent directory structure.

I found out that in order to be able to read bitrate from mp3 files in bash you need a tool called mp3info

mp3info -r m -p %r file.mp3
will output the bitrate 128 on the resulting line

a friendly member showed me a sample script which i modified slightly with my own directory structures that would do almost exactly what i wanted


mkdir "$good" "$bad"

find "$music" -type f -name '*.mp3' -print0 | while read -d  $'/0' file; do
	if [ "$(mp3info -r m -p %r  "$file")" -ls 129 ]; then
		cp --parents "$file" "$bad"
		cp --parents "$file" "$good"
when I run this script I get an error
read: 12: Illegal option -d
Now, I'm very new to scripting, so most of this is theory to me, but from what I see the find command is searching my music directory structure for files of type 'file' and named '.mp3' and then prints a null character at the end, which the while loop is looking for, once that happens all that data is scanned by mp3info and then sorted into directories based on the -lt statement

what i don't understand is why the delimiter -d command is giving an illegal output, or what the syntax error is in the loop statement. Can someone with more knowledge and expertise advise me if this is the correct way to accomplish what i want, and tell me where i'm going wrong in the syntax?

I appreciate it!
Old 03-25-2008, 10:39 AM   #2
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 730

Rep: Reputation: 75

Without looking in detail at your script, the easiest thing to try is to run it as:
I don't know anything about the data with which you are working, but the $'/0' in the read looks odd to me -- are you sure that that is correct? ... cheers, makyo

Last edited by makyo; 03-25-2008 at 10:44 AM.
Old 03-25-2008, 10:59 AM   #3
Registered: Mar 2004
Location: Us
Distribution: Ubuntu Dapper
Posts: 74

Original Poster
Rep: Reputation: 15
i think sh is the same as bash

and no... haha i'm absolutely not sure that the $'/0' is correct
Old 03-25-2008, 11:15 AM   #4
ReliaFree Maintainer
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
Are you using Bash and not a different shell? Have you tried removing the -d option to read? The error is telling you that your shell's version of read doesn't recognize the -d option.

I assume the $'/0' is supposed to represent the null character that is the delimiter being passed to -d. It should use a backward slash (\) IIRC.


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
BASH script for converting ogg to mp3. hacker supreme Programming 4 06-30-2009 03:39 PM
Bash mp3 to ogg script True`Colors Programming 6 07-20-2007 10:54 AM
Bash script to sort image files dtcs Programming 5 09-26-2006 10:50 PM
bash script to sort files by extension otheralex Programming 7 08-19-2005 03:40 AM
mp3 name 'squeezer' bash script ?? purpleburple Linux - General 7 12-12-2002 05:19 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:11 AM.

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