BASH: how to launch a program with parameters

Tags
bash, launch, parameter, shell scripts

 
Thread Tools Search this Thread
# 1  
Old 03-13-2008
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:

Code:
#!/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
Quote:
$ ./subtitleextract.sh Ying\ Xiong\ \(Hero\).mkv
Original Movie: Ying Xiong (Hero).mkv
srt File: Ying Xiong (Hero).srt
Track is: 3

Error: Missing track ID in argument 'Xiong'.
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!
# 2  
Old 03-13-2008
Try to escape the spaces in the variables $MOVIE and $SRTFILE before the extract command, for instance:

Code:
$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
# 3  
Old 03-14-2008
Quote:
Originally Posted by TinCanFury
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:

Code:
#!/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
Code:
$ ./subtitleextract.sh Ying\ Xiong\ \(Hero\).mkv 
Original Movie: Ying Xiong (Hero).mkv
srt File: Ying Xiong (Hero).srt
Track is: 3
Error: Missing track ID in argument 'Xiong'.

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

Quote your variables:
Code:
mkvextract tracks "$MOVIE" "${TRACK}:$SRTFILE"

# 4  
Old 03-14-2008
Quote:
Originally Posted by cfajohnson

Quote your variables:
Code:
mkvextract tracks "$MOVIE" "${TRACK}:$SRTFILE"

ah, didn't realize I could quote ${TRACK}:$SRTFILE all in one. thanks!
# 5  
Old 03-14-2008
Quote:
Originally Posted by TinCanFury
ah, didn't realize I could quote ${TRACK}:$SRTFILE all in one. thanks!

You could also quote them individually:
Code:
: "$TRACK":"$SRTFILE"

# 6  
Old 03-15-2008
Quote:
Originally Posted by cfajohnson

You could also quote them individually:
Code:
: "$TRACK":"$SRTFILE"

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

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Launch shell script with parameters from a webpage button black_fender Shell Programming and Scripting 2 09-01-2014 05:01 AM
Having trouble using expect to launch vpn program wblakenc Shell Programming and Scripting 2 06-24-2013 10:33 AM
Launch a text program inside a konsole at startup pierpier Shell Programming and Scripting 1 04-21-2013 05:47 PM
Input keyboard keys upon program launch brunobliss Shell Programming and Scripting 2 11-02-2012 07:46 AM
Update ksh .profile to launch bash Sivaswami Shell Programming and Scripting 1 11-15-2011 07:39 PM
Perl script timer on program launch vas28r13 Shell Programming and Scripting 1 08-01-2011 04:32 PM
Launch a windows program from perl script kingbp Shell Programming and Scripting 1 06-07-2011 11:00 PM
How do you close and launch X Window in the Bash shell? jacatone UNIX for Dummies Questions & Answers 1 07-18-2010 06:23 AM
Shell Script to launch C program gazmcc182 Shell Programming and Scripting 12 04-11-2010 05:04 PM
Problem with external program launch Zipi Programming 7 02-21-2009 01:30 PM
launch an executable from a C++ program nadiamihu Programming 2 11-03-2006 05:59 AM
Passing Parameters and getting values back from a c program to Shell script Rajeshsu Programming 5 08-22-2005 04:12 AM
parameters from my program in c to a .ksh script DebianJ Programming 2 05-16-2005 07:04 PM
how to launch program though telnet cbachman UNIX for Dummies Questions & Answers 3 03-21-2005 04:31 PM
Run a program and feed her parameters automaticly roco Shell Programming and Scripting 2 10-29-2002 07:16 PM