Error with Audio Conversion Bash Script

Good evening, I'm currently working on a BASH script to convert audio between file formats and I've come across a snag. At the beginning of the script, I'm having the system check to see if any files with the .m4a extension exist in the directory, and if so, it runs the script. If there are no .m4a extensions, it produces an error. Here is the script:

if [ -f *.m4a ]; then
    read -p "Enter bitrate value. [128/256/320] > " bitrate
    for f in *.m4a; do
    avconv -i "$f" -b "$bitrate"k "${f%.m4a}.mp3"
    done
    read -p "Would you like do remove the original .m4a files? [Y/N] > " remove
        if [[ $remove == [Yy] ]]; then
            rm *.m4a
        else
            exit 0
        fi
else
    echo "There are no .m4a files in the current directory."
fi

The directory I'm trying to test the script with has the following files:
01 The Veldt (Radio Edit).m4a 02 The Veldt (8 Minute Edit).m4a

When I run the script on this directory I get this error:

/home/kburkholder/bin/m4a2mp3: line 6: [: 01 The Veldt (Radio Edit).m4a: binary operator expected

Is there something I'm doing wrong with the file check part at the beginning of the script? I've tried using both double quotes, single quotes and no quotes at all and none are giving me the results I'm looking for. Any insight would be greatly appreciated! :smiley: Thanks!

-f takes one string, not zero or two or more.

I'd try it like this:

for f in *.m4a
do
    [ -f "$f" ] || break
    [ -z "$BITRATE" ] && read -p "Input bitrate" bitrate

    avconv -i "$f" -b "$bitrate"k "${f%.m4a}.mp3"
done