BASH: how to launch a program with parameters | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

BASH: how to launch a program with parameters

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-13-2008
TinCanFury TinCanFury is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 28 December 2008, 8:11 PM EST
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
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!
Sponsored Links
    #2  
Old 03-13-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 31 July 2014, 9:09 AM EDT
Location: The Netherlands
Posts: 7,692
Thanks: 120
Thanked 531 Times in 502 Posts
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
Sponsored Links
    #3  
Old 03-13-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 25 July 2014, 8:14 PM EDT
Location: Toronto, Canada
Posts: 2,877
Thanks: 0
Thanked 110 Times in 102 Posts
Quote:
Originally Posted by TinCanFury View Post
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
TinCanFury TinCanFury is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 28 December 2008, 8:11 PM EST
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by cfajohnson View Post

Quote your variables:

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

ah, didn't realize I could quote ${TRACK}:$SRTFILE all in one. thanks!
Sponsored Links
    #5  
Old 03-14-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 25 July 2014, 8:14 PM EDT
Location: Toronto, Canada
Posts: 2,877
Thanks: 0
Thanked 110 Times in 102 Posts
Quote:
Originally Posted by TinCanFury View Post
ah, didn't realize I could quote ${TRACK}:$SRTFILE all in one. thanks!

You could also quote them individually:

Code:
: "$TRACK":"$SRTFILE"

Sponsored Links
    #6  
Old 03-15-2008
TinCanFury TinCanFury is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 28 December 2008, 8:11 PM EST
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by cfajohnson View Post

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.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Launch a windows program from perl script kingbp Shell Programming and Scripting 1 06-07-2011 10:00 PM
Shell Script to launch C program gazmcc182 Shell Programming and Scripting 12 04-11-2010 04:04 PM
Problem with external program launch Zipi Programming 7 02-21-2009 12:30 PM
launch an executable from a C++ program nadiamihu Programming 2 11-03-2006 04:59 AM
how to launch program though telnet cbachman UNIX for Dummies Questions & Answers 3 03-21-2005 03:31 PM



All times are GMT -4. The time now is 07:51 AM.