I made a script to automate ffmpeg conversion from mkv > m4v > open the m4v in Subler.app to import the metadata manually, at which point I'll move the file into my iTunes library.
I use iTunes because I have two Apple TVs on the network and use a 2007 iMac to function as my media server. I locally ssh into this machine in order to execute this script.
This script fails if I enter a path with whitespace(s), or enter title for the movie that includes whitespace. How do I fix this script to accommodate whitespace? I know the syntax is sloppy, I’m very new to scripting, so any other pointers to make it run better would be appreciated :)
Here it is:
#! /bin/bash
#ffmp4
function convert {
ffmpeg -i $REPLY -strict -2 -c:v copy -c:a copy -c:s copy $PWD/out.m4v
}
function rename {
echo "Please Provide the Title:"
read -e; mv $PWD/out.mp4 $PWD/$REPLY.m4v
}
function subler {
open -a Subler.app $REPLY.m4v
}
cd ~/Public/ &&
while read -e; do
if [ ${REPLY: -4} == ".mkv" ];
then convert;
rename;
subler;
exit
else
echo "Error: This is not a valid response" && exit 1
fi
done
—————————
EDIT:
Question may still be a possible duplicate, but I’ve tried to use the syntax (both attempting “$REPLY” and “$(REPLY)”) in the linked answer and still failing to execute. The errors return either bad substitution for the […bracketed...] statement or my echo statement... Error:This is not a valid response…
$REPLYwith"$REPLY" and$PWDwith"$PWD"` etc. There are many tutorials that discuss shell quoting issues. – John1024 May 15 '16 at 05:43possible duplicateand your comment suggests…still getting error. I suspect thatif [ ${REPLY: -4} == ".mkv” ]is the issue. Perhaps brackets requires a different syntax? I’ve triedif [ "${REPLY: -4}" == ".mkv” ],if [ $"({REPLY: -4})”….– njboot May 15 '16 at 05:53[ "${REPLY: -4}" = ".mkv” ]and, if that gives you abad substitutionerror message, then you are not running the script underbash. Run the script asbash scriptname, notsh scriptname. – John1024 May 15 '16 at 06:28“$REPLY”variable in the other lines still returns error w/ whitespace. – njboot May 15 '16 at 06:31"and'. – l0b0 May 15 '16 at 09:40