linux - bash scripting: pass string containing multiple parameters and filenames with spaces to ffmpeg -


i have script generates text file entries like:

-ss 5.5 -i "/path/vid 1.mp4" -t 3 "/path/vid out1.mp4" 

but when call ffmpeg string attached fails. if quote variable ffmpeg considers entire string single option, error "option not found". if don't quote, reason ffmpeg ignores double quotes , reports "/path/vid :no such file or directory.

even though prints input correctly -i "/path/vid 1.mp4".

replacing double quotes around filenames single quotes doesn't help. when pass string zenity , manually copy terminal, works:

zenity --entry --entry-text "ffmpeg -nostdin $line2" 

so tried assigning entire command var , running bash $var or exec $var, no luck. assigning alias doesn't work either: "command not found"

solution joan estaban:

echo $stringvar | xargs ffmpeg 

a short full script demonstrating problem:

#!/bin/bash   fffile="/home/vume5/desktop/dwhelper/bud grafting animation.mp4"  line="-ss 4.920000 -i \"$fffile\" -t 60.000000 -map 0 -c:v copy -c:a copy \"$fffile.cut.mkv\""  zenity --entry --entry-text "$line"  ffmpeg $line  read dummy 

if arguments may contain spaces and/or other special characters, can use array store them.

e.g.:

params=(-ss 5.5 -i "/path/vid 1.mp4" -t 3 "/path/vid out1.mp4") mycommand "${params[@]}" 

Comments