You are not logged in.
Hello.
I can't figure out how to use single and double quotations in Bourne shell.
Here's a part of a script I'm writing to create a matroska video with several different subtitles :
title=`echo "$1" | sed 's/\.[^.]*$//'`
subs=''
for srt in "$title".*.srt; do
slang=`echo "$srt" | sed 's/.*\.\(...\)\.srt/\1/'`
subs="${subs} --language 0:$slang '$srt'"
done
mkvmerge -o "$title.mkv" $subs -S "$1"
When I type ./myscript 'Gadjo Dilo.avi', it should execute this command :
mkvmerge -o 'Gadjo Dilo.mkv' --language 0:eng 'Gadjo Dilo.eng.srt' --language 0:fre 'Gadjo Dilo.fre.srt' -S 'Gadjo Dilo.avi'
But, using set -x, I discovered it actually execute this :
mkvmerge -o 'Gadjo Dilo.mkv' --language 0:eng ''\''Gadjo' 'Dilo.eng.srt'\''' --language 0:fre ''\''Gadjo' 'Dilo.fre.srt'\''' -S 'Gadjo Dilo.avi'
How should I fix this ? I tried without success many different combinations of single and double quotes.
Thanks.
Last edited by pokraka (2010-08-22 20:29:35)
Offline
Remove spaces: Gadjo Dilo.mkv -> Gadjo_Dilo.mkv.
I think that's not what you're asking about, but it should help too, maybe even better :-)
Offline
Yes of course I know of this trick but I can't rename all my files.
Any other suggestion ?
Offline
Yes of course I know of this trick but I can't rename all my files.
Any other suggestion ?
Why can't you rename your files?
Instead of
mkvmerge -o "$title.mkv" $subs -S "$1"
try
mkvmerge -o "$title.mkv" "$subs" -S "$1"
(quotes around $subs added)
It helps a bit, but I honestly can't read your code - are all these filename mangling transformations really necessary?
Edit: I'm not using bourne shell, but neither bash nor dash wanted to cooperate fully.
subs="${subs} --language 0:$slang $srt"
(quotes around $srt removed)
Last edited by karol (2010-08-23 17:59:29)
Offline
Quick solution: use Bash instead of Bourne.
#!/bin/bash
title=${1%.*}
subs=()
for srt in "$title".*.srt; do
slang=${srt%.*}; slang=${slang##*.}
subs+=("--language" "0:$slang" "$srt")
done
mkvmerge -o "$title.mkv" "${subs[@]}" -S "$1"
I tested a little bit, but no refunds if your dog gets kicked.
Last edited by falconindy (2010-08-23 18:22:50)
Offline
What happens if you replace all of lines 3-8 with something simpler, like:
subs=$(ls | sed -n "s/$title\.\(...\)\.srt/--language 0:\1 '&'/p" | tr '\n' ' ')
Offline
Quick solution: use Bash instead of Bourne.
#!/bin/bash title=${1%.*} subs=() for srt in "$title".*.srt; do slang=${srt%.*}; slang=${slang##*.} subs+=("--language" "0:$slang" "$srt") done echo mkvmerge -o "$title.mkv" "${subs[@]}" -S "$1"
I tested a little bit, but no refunds if your dog gets kicked.
Does it work for filenames with spaces in them?
Offline
Does it work for filenames with spaces in them?
There's a reason I opted to use an array. Please take a visit to the Wooledge BashFAQ if you'd like to learn more about quoting in Bash.
What happens if you replace all of lines 3-8 with something simpler, like:
subs=$(ls | sed -n "s/$title\.\(...\)\.srt/--language 0:\1 '&'/p" | tr '\n' ' ')
You call this simpler? Not only is it even more confusing, you're succumbing to a major bash pitfall. Don't ever try to parse the output of ls.
Last edited by falconindy (2010-08-23 18:13:25)
Offline
@ falconindy
mkvmerge -o Gadjo Dilo.mkv --language 0:eng Gadjo Dilo.eng.srt --language 0:fre Gadjo Dilo.fre.srt -S Gadjo Dilo.avi
I think you need the single quotes: 'Gadjo Dilo.eng.srt'.
Edit: if you remove the echo part it will work :-)
Edit 2: One-liners are simpler by virtue of having less characters.
Last edited by karol (2010-08-23 18:18:46)
Offline
You call this [em]simpler[/em]?
I just meant shorter.
Don't [em]ever[/em] try to parse the output of ls.
Hey, I'll do what I want, thank you very much. (That said, I do know this is risky business, but I thought it might actually help in this case.)
Offline
Right. Typo on my part. I'll just leave these here...
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/ParsingLs
Last edited by falconindy (2010-08-23 18:23:41)
Offline