Thanks slacker. I've been doing my homework and by now I have my firsth not-so-begginer script functional, even when there are still things to do. I'd like to show it so you can help me to do it better, but since I didn't find any other place, I'll do it here.
Code:
#!/bin/bash
# To do:
# - Accept only y;Y/n;N as input for the questions
# - Simplify conditions
# - Learn about printf and replace echo with it
# - Use some lighter and more universal encoder instead of soundconverter
# Start of the script: verify that a route has been given as argument.
if [ -z "$1" ]
then
echo "No directory as been specified"
echo "Usage: all2mp3 [directory]"
exit 1
else
echo
echo "All the '.flac', '.wav' and '.wma' files in the directory will be encoded to '.ogg'"
echo
sleep 3s
fi
# Establish the NUMFILES variable, wich equals the number of files that can be encoded on the given route. If NUMFILES equals 0, then exit.
NUMFILES=`find $1 \( -iname "*.flac" -o -iname "*.wav" -o -iname "*.wma" \) -printf '%f\n\v' | grep -c ^`
if [ "$NUMFILES" = 0 ]
then
echo "No suitable files for encoding have been found"
exit 2
else
# Here find displays the files on the music directory and then the question of whether the action should be performed or not is asked.
find $1 \( -iname "*.flac" -o -iname "*.wav" -o -iname "*.wma" \) -printf '%f\n\v'
echo
echo "There are $NUMFILES files to be encoded"
echo
printf '\nDo you wish to procced? Y/N\n\v'
read -s -n 1 aval
# If yes, then finds all .wav, .wma and .flac files on the music directory and encodes them as .ogg, else, exit.
if [ $aval = "y" -a "Y" ]
then
find $1 \( -iname "*.flac" -o -iname "*.wav" -o -iname "*.wma" \) -execdir soundconverter -b -m audio/x-vorbis -s .ogg {} \;
echo "Encoding finished"
echo
sleep 3s
printf '\nDo you wish to remove the '.flac', '.wav' and '.wma' files? Y/N\n\v'
read -s -n 1 aval2
# If yes, then remove the original files, else leave them.
if [ $aval2 = "y" -a "Y" ]
then
find $1 \( -iname "*.flac" -o -iname "*.wav" -o -iname "*.wma" \) -delete
else
echo "No file has been deleted"
echo "Finished"
sleep 3s
fi
else
echo "No file has been encoded"
echo "Finished"
sleep 3s
exit 3
fi
fi
Any advice?