You are not logged in.

#1 2014-10-22 19:37:21

doblerone
Member
Registered: 2011-12-08
Posts: 215

[SOLVED] compare command output with a string

If I make

mkvmerge -i *.mp4

I have an output in which I can see the order for audio and video tracks in a .mp4 file.
Depending on that output, I'm trying to implement an if-else statement:

for i in *".mp4"; do

TRACKS="$(mkvmerge -i *".mp4")"

  if [$TRACKS == *0: audio*]; then

    i=${i%.mp4} 
    mkvmerge -o -v "$i.mkv" \
        --language 1:eng -a 1 -d 0 -S -T "$i.mp4" \
        --language 0:eng -s 0 -D -A -T "$i.en.srt" \
        --language 0:spa -s 0 -D -A -T "$i.es.srt" \
 
 else

    i=${i%.mp4} 
    mkvmerge -o -v "$i.mkv" \
        --language 1:eng -a 0 -d 1 -S -T "$i.mp4" \
        --language 0:eng -s 0 -D -A -T "$i.en.srt" \
        --language 0:spa -s 0 -D -A -T "$i.es.srt" \
        
  fi
  
done

But I'm doing something wrong and it doesn't take into account the comparison.

How can I solve it?

Regards

Last edited by doblerone (2014-10-22 20:47:22)

Offline

#2 2014-10-22 19:49:16

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] compare command output with a string

First, you need spaces between the brackets:

if [ $TRACKS == *0: audio* ]; then

Then, if you are going to use `[` rather than the more robust `[[`, you need to quote $TRACKS.

See: http://mywiki.wooledge.org/BashGuide/Te … nditionals


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-10-22 20:08:10

doblerone
Member
Registered: 2011-12-08
Posts: 215

Re: [SOLVED] compare command output with a string

I change it, but it doesn't work neither:

TRACKS="$(mkvmerge -i *".mp4")"

  if [[ $TRACKS == *0: audio* ]]; then

    i=${i%.mp4} 
    mkvmerge -o -v "$i.mkv" \
        --language 1:eng -a 0 -d 1 -S -T "$i.mp4" \
        --language 0:eng -s 0 -D -A -T "$i.en.srt" \
        --language 0:spa -s 0 -D -A -T "$i.es.srt" \

  else

    i=${i%.mp4} 
    mkvmerge -o -v "$i.mkv" \
        --language 1:eng -a 1 -d 0 -S -T "$i.mp4" \
        --language 0:eng -s 0 -D -A -T "$i.en.srt" \
        --language 0:spa -s 0 -D -A -T "$i.es.srt" \

  fi
subs+mkvmerge.sh: line 34: syntax error in conditional expression
subs+mkvmerge.sh: line 34: syntax error near `audio*'
subs+mkvmerge.sh: line 34: `  if [[ $TRACKS == *0: audio* ]]; then'

Offline

#4 2014-10-22 20:21:27

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,646

Re: [SOLVED] compare command output with a string

Read the link jasonwryan posted. Pay particular attention to quoting (the use of " " around variables and expressions).

Offline

#5 2014-10-22 20:42:18

doblerone
Member
Registered: 2011-12-08
Posts: 215

Re: [SOLVED] compare command output with a string

2ManyDogs wrote:

Read the link jasonwryan posted. Pay particular attention to quoting (the use of " " around variables and expressions).

I got it!!!

if [[ $TRACKS = *"0: audio"* ]]; then

Thanks guys!

Last edited by doblerone (2014-10-22 20:46:12)

Offline

#6 2014-10-22 20:44:56

bstaletic
Member
Registered: 2014-02-02
Posts: 658

Re: [SOLVED] compare command output with a string

Your TRACKS doesn't have the value you expect it to have. Now reread your script and the link posted above.

Offline

Board footer

Powered by FluxBB