I have a simple wrapper script to play videos, where my script tries to find subtitle file to a given video file (if it exists). Given video name, I am looking for same name, only ending in .vtt extension instead of video format extension:
#!/bin/sh
video_file="$1"
sub_file="$(/bin/find -name ${video_file%.*}.*.vtt)"
if [ -f "$sub_file" ] ; then
echo "subtitles found: $sub_file"
else
echo "subtitles not found"
fi
If multiple sub files exist, ie: foo.en.vtt, foo.de.vtt, I want to use the first one found.
The problem is the above script only works when zero or one matching .vtt files exist. If two exist, then find returns following error:
/bin/find: paths must precede expression: `2207-_-20220620.en.vtt'
/bin/find: possible unquoted pattern after predicate `-name'?
subtitles not found
The problem seems to be that find gets two parameters for the -name predicate. But I cannot quote the pattern ${video_file%.*}.*.vtt because then the wildcard * would be interpreted literally.
I have tried using -regex predicate with same results
How can I achieve what I want in my script?