LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 08-26-2005, 11:18 PM   #1
hellomynameisphil
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':
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
 
Old 08-26-2005, 11:35 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

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

Last edited by spooon; 08-26-2005 at 11:37 PM.
 
Old 08-27-2005, 03:41 AM   #3
dub.wav
Member
 
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:
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.
 
  


Reply



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 04:28 PM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM
simple scripting question wedgeworth Programming 6 02-04-2004 10:30 AM
Shell Scripting Question jester_69 Programming 13 11-05-2003 06:55 PM
Shell Scripting Question chrisk5527 Linux - General 12 07-09-2003 03:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration