I'm writing a script that will automatically sort my albums on my NAS server and encountered the following error. Whenever I have a space in an album name I'm getting an error. Albums can be either called "Artist_-_Album" or "Artist One - Album"
#!/bin/bash
for file in /home/peres/Documents/*
do
name=$(basename "$file")
number=${#name}
#sort if artist and album contains "_-_"
if [[ $name == *"_-_"* ]]
then
echo "Album detected!"
artistname=${name%%_-_*}
albumname=${name##*_-_}
mkdir -p $name/$albumname
mv $name $artistname
fi
#sort if artist and album contains " - "
if [[ $name == *" - "* ]]
then
echo "Album detected!"
artistname=${name%% - *}
albumname=${name##* - }
mkdir -p $name/$albumname
mv $name $artistname
fi
done