I'm trying to search my Movies folder to find the immediate folder of the .MKV file I'm searching for. The below works (echo 5) to save the immediate folder as a variable, BUT, it does not work if $mkvfile contains spaces. I've been unsuccessful in getting $moviename to work if $mkvfile contains spaces.
searchdir="/mnt/storagepool/storage/downloads"
moviedir="/mnt/storagepool/storage/media/Movies"
#MKVs in root folder
for filename in $searchdir/*.mkv; do
#Get .MKV file from root of the downloads/search directory.
mkvfile="$(basename $filename)"
#echo 2 $mkvfile
#Search for the MKV file in the media/Movies directory to find the corresponding movie folder name
#echo 3 "${moviedir}"
#echo 4 $mkvfile
moviename=$(find "${moviedir}" -name '$moviedir' -prune -o -name "$mkvfile" -exec dirname {} \;)
echo 5 "${moviename}"
done
$filename
:mkvfile="$(basename "$filename")"
– schrodingerscatcuriosity Oct 28 '19 at 17:44$moviedir
in-name '$moviedir'
will not be expanded due to the single quotes. – Kusalananda Oct 28 '19 at 18:44