[GTALUG] Bash Problem

Michael Galea michael at galeahome.ca
Sat Jan 7 19:38:12 EST 2017


On 01/07/17 19:25, Stephen via talk wrote:
> I am new to Bash scripts.
>
> I am trying to create a script to use avconv to convert mkv files to mp4
> file.
>
> Run one at a time the command runs fine.
>
> When I execute this script I get an error about an unknown parameter. I
> am guessing that the expansion with the filename variables is failing.
>
> Can someone help me correct?
>
> Thank you!
>
> #!/bin/bash
> # Usage: convert file to mp4
> shopt -s nullglob
> ext='.mp4'
> for f in *.mkv
> do
>    base=$(basename $f .mkv)
>    nFname=$base".mp4"
>    echo $nFname
>    avconv "-i $f -c:v libx264 -c:a copy $nFname"
> done
>
>

Shouldn't you be quoting $f and $nFname separately, e.g.
  avconv -i "$f" -c:v libx264 -c:a copy "$nFname"
otherwise filenames with spaces will see -i catch only part of the filename.

Try adding echo in front of the avconv command and see what would be 
executed from within the script.

-- 
Michael Galea


More information about the talk mailing list