[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell script question

On Sun, Oct 12, 2003 at 11:18:11PM -0400, Jeff Elkins wrote:
> In the same vein, I'm working through a list of mp3s where some of them need 
> re-encoding. First, I convert them to wavs with this script fragment:
> mpg123 -b 10000 -s "$1" | sox -t raw -r 44100 -s -w -c2 - "$2"
> where I feed the script $1 (input) and $2 (output). In every case, $1 and $2 
> are the same, except for $2 I want the output filename to have a .wav 
> extension.
> Could I alter the script to eliminate entering $2, since the basic filename is 
> the same?

Here's a little expression that strips off any trailing ".<extension>"
from $1 and tacks on ".wav".


Look under "Parameter Expansion" in bash(1) for how this works. Note
that some of the constructions there are bash-specific; you can compare
with "Parameter Expansion in dash(1) to get the portable subset.


Colin Watson                                  [cjwatson@flatline.org.uk]

Reply to: