BASH: how to launch a program with parameters

Hi, I'm a pretty big fan of BASH scripting. I've got a bunch I use for random things and lately a couple issues have been plaguing me.

Both are somewhat related, in that they deal with filenames with spaces and "escaped" characters and with launching a program with command line arguements (which invariably include these filenames).

for instance. I have a bunch of MKV movies with embedded subtitles. I'd like to extract the subtitles into their own SRT file. so I've got this basic script written:

#!/bin/bash

MOVIE=$1
echo "Original Movie: $MOVIE"
SRTFILE=${MOVIE/%mkv/srt}
echo "srt File: $SRTFILE"

TRACK=`mkvinfo "$MOVIE" | grep subtitle -B3 | grep Track\ number\:\ | sed -e 's$
#echo "Track is $TRACK"

if [[ "$TRACK" -gt "0" ]]
then
        echo "Track is: $TRACK"
        mkvextract tracks $MOVIE ${TRACK}:$SRTFILE
else
        echo "No subtitle track!"
fi

which gives me

it should be running
mkvextract tracks Ying\ Xiong\ \(Hero\).mkv 3:Ying\ Xiong\ \(Hero\).srt
but obviously isn't.

The other script I've got that I'd love to get working is one I wrote to combine a series of avi files using avidemux. to do this I wrote a script that takes the input files as the arguements, deduces the output file name and then because of avidemux's arguement procedure I have it create a set of strings that it needs to append to the call to avidemux for each file being added to the original. I have a similar problem with this script as well, but with many more arguements involved. What I've done with this one is have it echo the required command to run which I can then copy and paste and it works fine, but it would be much nicer if I could get it to actually *launch* said command.

phew, hopefully someone that knows how to solve this bothered to read through this long post, and to you sir, I thank and congratulate you, especially if you have an answer to my troubles!

thanks!

Try to escape the spaces in the variables $MOVIE and $SRTFILE before the extract command, for instance:

$MOVIE_1=`echo $MOVIE|sed 's// /\\ /g'`
$SRTFILE_1=`echo $SRTFILE|sed 's// /\\ /g'`

mkvextract tracks $MOVIE_1 ${TRACK}:$SRTFILE_1

For your second question you have to provide further information. I should start a new thread.

Regards

Quote your variables:

mkvextract tracks "$MOVIE" "${TRACK}:$SRTFILE"

ah, didn't realize I could quote ${TRACK}:$SRTFILE all in one. thanks!

You could also quote them individually:

: "$TRACK":"$SRTFILE"

I tried that, didn't work, quoting as a whole string did though. don't know why/what the difference is though.