LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Simple Shell Scripting Question (http://www.linuxquestions.org/questions/programming-9/simple-shell-scripting-question-357411/)

hellomynameisphil 08-26-2005 11:18 PM

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':
Code:

#!/bin/bash

# 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'   
do
        /sw/bin/normalize --mix --verbose --verbose $filename
done

The output of this script is as follows:
Code:

/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.

Phil

spooon 08-26-2005 11:35 PM

try using
Code:

`ls -R`
or
Code:

$(ls -R)

dub.wav 08-27-2005 03:41 AM

ls -R won't work like you expect. Instead, try something like this:
Code:

for filename in $(find . -iname '*.mp3')   
do
        /sw/bin/normalize --mix --verbose --verbose "$filename"
done

If you need to handle filenames with spaces, you have to set the IFS, or Internal File Separator variable.
Code:

IFS=$'\n' # tell the shell to split filenames at newline
for filename in $(find . -iname '*.mp3')   
do
        /sw/bin/normalize --mix --verbose --verbose "$filename"
done

Normally you'd make sure to restore IFS to the original value, but in this case it doesn't affect anything else.


All times are GMT -5. The time now is 02:18 AM.