Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 08-27-2005, 12:18 AM   #1
LQ Newbie
Registered: Aug 2005
Distribution: CRUX and Arch
Posts: 11

Rep: Reputation: 0
Simple Shell Scripting Question

Hi all,

I am trying to run a program called "normalize" in a bash script. "normalize" normalizes a set of sound files so they have a comparable volume, which is handy when burning mix CD's for example. However, the program only looks at sound files in a particular directory, and for technical reasons, I need to run it on sound files across several directories. So I'm trying to use the following simple shell script to run the program on each filename in the output of 'ls -R':

# This is a shell script to facilitate batch normalization using Chris Vaill's command-line normalize program for *nix. For each subdirectory of the directory in which the program is run, it will enter that directory and normalize all the sound files in it.

for filename in 'ls -R'    
        /sw/bin/normalize --mix --verbose --verbose $filename
The output of this script is as follows:
/sw/bin/normalize: invalid option -- R
Usage: normalize [OPTION]... [FILE]...
Try `normalize --help' for more information.
I have almost no experience writing shell scripts, but my understanding is that what should happen is that the script should run 'ls -R', find all the filenames and run normalize on each of them. But somehow, "normalize" is getting the -R option passed to it that is meant for 'ls'. Is there a better way to do this, or am I basically on the right track but have to tweak my code? TIA.

Old 08-27-2005, 12:35 AM   #2
Senior Member
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
try using
`ls -R`
$(ls -R)

Last edited by spooon; 08-27-2005 at 12:37 AM.
Old 08-27-2005, 04:41 AM   #3
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
ls -R won't work like you expect. Instead, try something like this:
for filename in $(find . -iname '*.mp3')    
        /sw/bin/normalize --mix --verbose --verbose "$filename"
If you need to handle filenames with spaces, you have to set the IFS, or Internal File Separator variable.
IFS=$'\n' # tell the shell to split filenames at newline
for filename in $(find . -iname '*.mp3')    
        /sw/bin/normalize --mix --verbose --verbose "$filename"
Normally you'd make sure to restore IFS to the original value, but in this case it doesn't affect anything else.


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
Very simple BASH scripting question clickster Linux - Newbie 6 11-23-2005 05:28 PM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 02:44 PM
simple scripting question wedgeworth Programming 6 02-04-2004 11:30 AM
Shell Scripting Question jester_69 Programming 13 11-05-2003 07:55 PM
Shell Scripting Question chrisk5527 Linux - General 12 07-09-2003 04:36 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:32 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