[GLLUG] Syntax question
Charles Ulrich
charles at bityard.net
Sat Mar 1 17:44:14 EST 2008
On Sat, Mar 1, 2008 at 5:13 PM, Stanley C. Mortel <mortel at cyber-nos.com> wrote:
> OK, I'm trying to use lame to convert .wav files to .mp3 files. Without an
> output file argument it names the thing 1.wav.mp3 when I want it to be
> 1.mp3. So I've been trying to use "basename" to fix this but that command
> seems to embed a carraige return that I can't get rid of. Here is the script:
>
> #!/bin/bash
>
> for f in *.wav ;
> do
> g = | basename $f .wav ;
> echo $g.mp3
> lame $f $g.mp3 ;
> done
If you're using bash, your assignment to $g shouldn't work... on the
version of bash here on my system, you can't have a space between the
variable name and the assignment operator (=), or else bash thinks 'g'
is a command.
Basename shouldn't be inserting a newline. The indentation got a
little messed up, so I might be misinterpreting the intentions of your
code, but think either the echo is inserting the newline or it has to
do with the way you're calling basename using a pipe character. It's
worth noting that I don't think I've seen the pipe used this way
before... See if something like this works out better:
for f in *.wav ;
do
g=`basename $f .wav`
echo $g.mp3
lame $f $g.mp3
done
The main change is that the pipe was replaced by backticks. You can also use:
g=$(basename $f .wav)
in most (all?) bourne-compatible shells.
Charles
More information about the linux-user
mailing list