Extend Musicbrainz multi-artist support
[abcde.git] / abcde
diff --git a/abcde b/abcde
index 3ad7ff7..384954a 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -20,8 +20,9 @@ echo "Usage: abcde [options] [tracks]"
 echo "Options:"
 echo "-1     Encode the whole CD in a single file"
 echo "-a <action1[,action2]...>"
-echo "       Actions to perform:"
-echo "       cddb,read,getalbumart,embedalbumart,normalize,encode,tag,move,replaygain,playlist,clean"
+echo "       Actions to perform, comma separated:"
+echo "       (cddb,read,getalbumart,embedalbumart,normalize,encode,"
+echo "       tag,move,replaygain,playlist,clean)"
 #echo "-A     Experimental actions (retag, transcode)"
 echo "-b     Enable batch normalization"
 echo "-B     Embed albumart (this also activates getalbumart)"
@@ -48,10 +49,13 @@ echo "-m     Modify playlist to include CRLF endings, to comply with some player
 echo "-n     No lookup. Don't query CDDB, just create and use template"
 echo "-N     Noninteractive. Never prompt for anything"
 echo "-o <type1[,type2]...>"
-echo "       Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta,aiff). Defaults to vorbis"
+echo "       Output file type(s), comma separated"
+echo "       (vorbis,mp3,flac,spx,mpc,wav,m4a,opus,mka,wv,ape,mp2,tta,aiff)."
+echo "       Defaults to vorbis"
 echo "-p     Pad track numbers with 0's (if less than 10 tracks)"
 echo "-P     Use UNIX pipes to read+encode without wav files"
-echo "-Q     Select CDDBMETHOD method(s) from the command line. Choose from any/all of musicbrainz,cddb,cdtext. Defaults to musicbrainz".
+echo "-Q     CD lookup method(s), comma separated"
+echo "       (musicbrainz,cddb,cdtext). Defaults to musicbrainz".
 echo "-r <host1[,host2]...>"
 echo "       Also encode on these remote hosts"
 echo "-s <field>"
@@ -96,22 +100,22 @@ log ()
 # Functions to replace the need of seq, which is too distribution dependent.
 f_seq_row ()
 {
-       i="$1"
-       while [ "$i" -le "$2" ]
+       i=$1
+       while [ $i -le $2 ]
        do
-               echo "$i"
-               i=$(("$i" + 1))
+               echo $i
+               i=$(( $i + 1 ))
        done
 }
 
 f_seq_line ()
 {
-       i="$1"
+       i=$1
        if echo "$i" | grep "[[:digit:]]" > /dev/null 2>&1 ; then
-               while [ "$i" -le "$2" ]
+               while [ $i -le $2 ]
                do
                        printf "%d " "$i"
-                       i=$(("$i" + 1))
+                       i=$(( $i + 1 ))
                done
                echo
        else
@@ -140,7 +144,7 @@ get_last()
                        last=$stdin
                done
        else
-               for last in "$@" ; do :; done
+               for last in $@ ; do :; done
        fi
        echo "$last"
 }
@@ -215,26 +219,36 @@ checkerrors ()
 }
 
 # page [file]
-# Finds the right pager in the system to display a file
+# Display a file. If it's too long to fit the current terminal size,
+# find the right pager in the system and use it
 page ()
 {
        PAGEFILE="$1"
-       # Use the debian sensible-pager wrapper to pick the pager
-       # user has requested via their $PAGER environment variable
-       if [ -x "/usr/bin/sensible-pager" ]; then
-               /usr/bin/sensible-pager "$PAGEFILE"
-       elif [ -x "$PAGER" ]; then
-               # That failed, try to load the preferred editor, starting
-               # with their PAGER variable
-               $PAGER "$PAGEFILE"
-               # If that fails, check for less
-       elif [ -x /usr/bin/less ]; then
-               /usr/bin/less -f "$PAGEFILE"
-               # more should be on all UNIX systems
-       elif [ -x /bin/more ]; then
-               /bin/more "$PAGEFILE"
+       local NUM_LINES=$(wc -l < "$PAGEFILE")
+
+       # Is the text long enough to need a pager?
+       if [ "$NUM_LINES" -ge $LINES ]; then
+               # Yes!
+               # Use the debian sensible-pager wrapper to pick the pager user
+               # has requested via their $PAGER environment variable
+               if [ -x "/usr/bin/sensible-pager" ]; then
+                       /usr/bin/sensible-pager "$PAGEFILE"
+               elif [ -x "$PAGER" ]; then
+                       # That failed, try to load the preferred pager, starting
+                       # with their PAGER variable
+                       $PAGER "$PAGEFILE"
+                       # If that fails, check for less
+               elif [ -x /usr/bin/less ]; then
+                       /usr/bin/less -f "$PAGEFILE"
+                       # more should be on all UNIX systems
+               elif [ -x /bin/more ]; then
+                       /bin/more "$PAGEFILE"
+               else
+                       # No bananas, just cat the thing
+                       cat "$PAGEFILE" >&2
+               fi
        else
-               # No bananas, just cat the thing
+               # No, just cat the thing
                cat "$PAGEFILE" >&2
        fi
 }
@@ -394,23 +408,21 @@ diffentries ()
                if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$CDDBDIFFCHOICES" ] || \
                   [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$CDDBDIFFCHOICES" ] || \
                   [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
-                       echo "Invalid diff range. Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
+                       echo "Invalid diff range." >&2
+                       echo "Please select two comma-separated numbers between 1 and $CDDBDIFFCHOICES" >&2
                else
                        # We parse the 2 choices to diff, store them in temporary files and diff them.
                        for PARSECHOICE in $(echo "$CDDBDIFFCHOICE" | tr , \ ); do
                                do_cddbparse "${ABCDETEMPDIR}/$FILENAME.$PARSECHOICE" > "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE"
                        done
                        echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/$FILENAME.diff"
-                       $DIFF $DIFFOPTS "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE1" "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/$FILENAME.diff"
-                       NUM_LINES=$(wc -l < "${ABCDETEMPDIR}/$FILENAME.diff")
-                       if [ "$NUM_LINES" -ge $LINES ]; then
-                               page "${ABCDETEMPDIR}/$FILENAME.diff"
-                       else
-                               cat "${ABCDETEMPDIR}/$FILENAME.diff" >&2
-                       fi
+                       $DIFF $DIFFOPTS "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE1" \
+                                 "${ABCDETEMPDIR}/$FILENAME.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/$FILENAME.diff"
+                       page "${ABCDETEMPDIR}/$FILENAME.diff"
                fi
        else
-               echo "The diff program was not found in your path. Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
+               echo "The diff program was not found in your path." >&2
+               echo "Please choose a number between 0 and $CDDBDIFFCHOICES." >&2
        fi
 }
 
@@ -541,7 +553,7 @@ do_replaygain()
                        REPLAYINDEX=0
                        for UTRACKNUM in $TRACKQUEUE
                        do
-                               CDDBTRACKNUM=$(("$UTRACKNUM" - 1))
+                               CDDBTRACKNUM=$(expr "$UTRACKNUM" - 1) # Unpad
                                getcddbinfo TRACKNAME
                                splitvarious
                                TRACKFILE="$(mungetrackname "$TRACKNAME")"
@@ -646,7 +658,7 @@ splitvarious ()
 }
 
 do_getgenreid () {
-       local genre=$(echo "${@}" | tr '[A-Z]' '[a-z]')
+       local genre=$(echo "${@}" | tr 'A-Z' 'a-z')
        local id=""
        case ${genre} in
                "blues")                 id=0 ;;
@@ -939,13 +951,15 @@ do_tag ()
                                        fi
                                        ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE \
                                                $VORBISCOMMENT $VORBISCOMMENTOPTS -w \
-                                               "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
+                                               "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
+                                               "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
                                        # Doublecheck that the commented file was created
                                        # successfully before wiping the original
                                        if [ -f "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER" ]; then
                                                rm -f "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER"
                                        else
-                                               mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
+                                               mv "${ABCDETEMPDIR}/track$1.uncommented.$OGGOUTPUTCONTAINER" \
+                                                  "${ABCDETEMPDIR}/track$1.$OGGOUTPUTCONTAINER"
                                        fi
                                        ;;
                        esac
@@ -986,8 +1000,9 @@ do_tag ()
                                        *)   echo COMMENT="$COMMENTOUTPUT";;
                                esac
                        fi
-                       ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $METAFLAC $METAFLACOPTS ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
-                       --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
+                       ) | run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE $METAFLAC $METAFLACOPTS \
+                                                       ${IMPORTCUESHEET:+--import-cuesheet-from="${ABCDETEMPDIR}/$CUEFILE"} \
+                                                       --import-tags-from=- "${ABCDETEMPDIR}/track$1.$FLACOUTPUTCONTAINER"
                        ;;
                spx)
                        run_command "tagtrack-$OUTPUT-$1" true
@@ -1002,16 +1017,18 @@ do_tag ()
                        # This tagging syntax is suitable for Robert Muth's application 'apetag', the Monkey's Audio 
                        # Console port (mac) used for encoding does not have the ability to tag.
                        run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$APETAG" -i "${ABCDETEMPDIR}/track$1.ape" -m overwrite \
-                       -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track="${TRACKNUM:-$1}" \
-                       -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"} 
+                                               -p artist="$TRACKARTIST" -p album="$DALBUM" -p title="$TRACKNAME" -p track="${TRACKNUM:-$1}" \
+                                               -p year="$CDYEAR" -p genre="$CDGENRE" ${COMMENTOUTPUT:+-p comment="$COMMENTOUTPUT"} 
                        ;;
                mp2)
                        # Using Mutagen's mid3v2 for tagging with id3v2.4.0. Interesting enough vlc, MPlayer and XMMS ignore
                        # these tags but they are read by Audacious, Xine, Aqualung, mediainfo, ffplay, ffprobe. FFmpeg does
                        # not currently tag mp2 audio so twolame and FFmpeg will both use mid3v2...
-                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
-                       -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
-                       "${ABCDETEMPDIR}/track$1.mp2"
+                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
+                                               -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
+                                               -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
+                                               ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
+                                               "${ABCDETEMPDIR}/track$1.mp2"
                        ;;
                aac)
                        run_command "tagtrack-$OUTPUT-$1" true
@@ -1024,9 +1041,11 @@ do_tag ()
                                        ;;
                                neroAacEnc)
                                        # Tag post encode with neroAacTag...
-                                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$NEROAACTAG" "${ABCDETEMPDIR}/track$1.m4a" \
-                                       -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" -meta:title="$TRACKNAME" -meta:track="${TRACKNUM:-$1}" \
-                                       -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
+                                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$NEROAACTAG" \
+                                                               "${ABCDETEMPDIR}/track$1.m4a" \
+                                                               -meta:artist="$TRACKARTIST" -meta:album="$DALBUM" \
+                                                               -meta:title="$TRACKNAME" -meta:track="${TRACKNUM:-$1}" \
+                                                               -meta:year="$CDYEAR" -meta:genre="$CDGENRE" -meta:comment="$COMMENT"
                                        ;;
                                faac)
                                        run_command "tagtrack-$OUTPUT-$1" true
@@ -1037,9 +1056,11 @@ do_tag ()
                                fhgaacenc)
                                        # Tag post encode with AtomicParsley. Note that previous problems with seg fault when using
                                        # 'overWrite' cannot be reproduced with newer versions: https://bitbucket.org/wez/atomicparsley
-                                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$ATOMICPARSLEY" "${ABCDETEMPDIR}/track$1.m4a" \
-                                       --artist="$TRACKARTIST" --album="$DALBUM" --title="$TRACKNAME" --tracknum="${TRACKNUM:-$1}" \
-                                       --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" $ATOMICPARSLEYOPTS --overWrite
+                                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$ATOMICPARSLEY" \
+                                                               "${ABCDETEMPDIR}/track$1.m4a" --artist="$TRACKARTIST" --album="$DALBUM" \
+                                                               --title="$TRACKNAME" --tracknum="${TRACKNUM:-$1}" \
+                                                               --year="$CDYEAR" --genre="$CDGENRE" --comment="$COMMENT" \
+                                                               $ATOMICPARSLEYOPTS --overWrite
                                        ;;
                                ffmpeg)
                                        run_command "tagtrack-$OUTPUT-$1" true
@@ -1048,9 +1069,10 @@ do_tag ()
                        ;;
                tta)
                        # We use mid3v2 tagging for True Audio:
-                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" -a "$TRACKARTIST" -t "$TRACKNAME" \
-                       -y "$CDYEAR" -g "$CDGENRE" -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} \
-                       "${ABCDETEMPDIR}/track$1.tta"
+                       run_command "tagtrack-$OUTPUT-$1" nice $ENCNICE "$MID3V2" --verbose -A "$DALBUM" \
+                                               -a "$TRACKARTIST" -t "$TRACKNAME" -y "$CDYEAR" -g "$CDGENRE" \
+                                               -T "${TRACKNUM:-$1}/$TRACKS" ${TPE2:+--TPE2 "$TPE2"} \
+                                               ${COMMENTOUTPUT:+--comment="$COMMENTOUTPUT"} "${ABCDETEMPDIR}/track$1.tta"
                        ;;
                wav)
                        run_command "tagtrack-$OUTPUT-$1" true
@@ -1079,18 +1101,18 @@ do_nogap_encode ()
                                (
                                        cd "${ABCDETEMPDIR}"
                                        TRACKFILES=
-                                       for UTRACKNUM in $TRACKQUEUE
+                                       for THISTRACKNUM in $TRACKQUEUE
                                        do
-                                               TRACKFILES="$TRACKFILES track$UTRACKNUM.wav"
+                                               TRACKFILES="$TRACKFILES track$THISTRACKNUM.wav"
                                        done
                                        nice $ENCNICE $MP3ENCODER $MP3ENCODEROPTS --nogap $TRACKFILES
                                        RETURN=$?
                                        if [ "$RETURN" != "0" ]; then
                                                echo "nogap-encode: $MP3ENCODER returned code $RETURN" >> "${ABCDETEMPDIR}/errors"
                                        else
-                                               for UTRACKNUM in $TRACKQUEUE
+                                               for THISTRACKNUM in $TRACKQUEUE
                                                do
-                                                       run_command "encodetrack-$OUTPUT-$UTRACKNUM" true
+                                                       run_command "encodetrack-$OUTPUT-$THISTRACKNUM" true
                                                done
                                        fi
                                )
@@ -1238,9 +1260,10 @@ do_encode ()
                                        opusenc)
                                        # Tag the file at encode time, as it can't be done after encoding.
                                                if [ "$DOTAG" = "y" ]; then
-                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS --artist "$TRACKARTIST" \
-                                                       --album "$DALBUM" --title "$TRACKNAME" --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
-                                                       ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
+                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS \
+                                                                                --artist "$TRACKARTIST" --album "$DALBUM" --title "$TRACKNAME" \
+                                                                                --genre "$CDGENRE" --date "$CDYEAR" --comment TRACKNUMBER="$1" \
+                                                                                ${COMMENT:+--comment COMMENT="$COMMENT"} "$IN" "$OUT"
                                                else
                                                        $RUN_COMMAND nice $EFFECTIVE_NICE $OPUSENCODER $OPUSENCODEROPTS "$IN" "$OUT"
                                                fi
@@ -1256,9 +1279,11 @@ do_encode ()
                                case "$MKAENCODERSYNTAX" in
                                ffmpeg)
                                        if [ "$DOTAG" = "y" ]; then
-                                               $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS -metadata artist="$TRACKARTIST" \
-                                               -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
-                                               -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
+                                               $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS \
+                                                                        -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
+                                                                        -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
+                                                                        -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
+                                                                        -metadata comment="$COMMENT" "$OUT"
                                        else
                                                $RUN_COMMAND nice $EFFECTIVE_NICE $MKAENCODER -i "$IN" $MKAENCODEROPTS "$OUT"
                                        fi
@@ -1269,9 +1294,11 @@ do_encode ()
                                case "$AIFFENCODERSYNTAX" in
                                ffmpeg)
                                        if [ "$DOTAG" = "y" ]; then
-                                               $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS -metadata artist="$TRACKARTIST" \
-                                               -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
-                                               -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT"
+                                               $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS \
+                                                                        -metadata artist="$TRACKARTIST" -metadata album="$DALBUM" \
+                                                                        -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" \
+                                                                        -metadata date="$CDYEAR" -metadata genre="$CDGENRE" \
+                                                                        -metadata comment="$COMMENT" "$OUT"
                                        else
                                                $RUN_COMMAND nice $EFFECTIVE_NICE $AIFFENCODER -i "$IN" $AIFFENCODEROPTS "$OUT"
                                        fi
@@ -1301,8 +1328,9 @@ do_encode ()
                                fi
                                # Tag the file at encode time, as it can't be done after encoding.
                                if [ "$DOTAG" = "y" ]; then
-                                       $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS --author "$TRACKARTIST" --title "$TRACKNAME" \
-                                       ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
+                                       $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS \
+                                                                --author "$TRACKARTIST" --title "$TRACKNAME" \
+                                                                ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
                                else
                                        $RUN_COMMAND nice $EFFECTIVE_NICE $SPEEXENCODER $SPEEXENCODEROPTS "$IN" "$OUT"
                                fi
@@ -1310,8 +1338,10 @@ do_encode ()
                        mpc)
                                # Tag the file inline at encode time.
                                if [ "$DOTAG" = "y" ]; then
-                                       $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
-                                       --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
+                                       $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS \
+                                                                --artist "$TRACKARTIST" --album "$DALBUM" \
+                                                                --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
+                                                                --year "$CDYEAR" ${COMMENT:+--comment "$COMMENT"} "$IN" "$OUT"
                                else
                                        $RUN_COMMAND nice $EFFECTIVE_NICE $MPCENCODER $MPCENCODEROPTS "$IN" "$OUT"
                                fi
@@ -1331,17 +1361,21 @@ do_encode ()
                        case "$WVENCODERSYNTAX" in
                                wavpack)
                                        if [ "$DOTAG" = "y" ]; then
-                                               $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
-                                               -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
+                                               $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS \
+                                                                        -w Artist="$TRACKARTIST" -w Album="$DALBUM" \
+                                                                        -w Title="$TRACKNAME" -w Track="$1" -w Genre="$CDGENRE" \
+                                                                        -w Year="$CDYEAR" ${COMMENT:+-w Comment="$COMMENT"} "$IN" -o "$OUT"
                                        else
                                                $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER $WVENCODEROPTS "$IN" -o "$OUT"
                                        fi
                                ;;
                                ffmpeg)
                                        if [ "$DOTAG" = "y" ]; then
-                                               $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS -metadata artist="$TRACKARTIST" \
-                                               -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
-                                               -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT" 
+                                               $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS \
+                                                                        -metadata artist="$TRACKARTIST" \
+                                                                        -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
+                                                                        -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
+                                                                        -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT" 
                                        else 
                                                $RUN_COMMAND nice $EFFECTIVE_NICE $WVENCODER -i "$IN" $WVENCODEROPTS "$OUT"
                                        fi
@@ -1354,11 +1388,11 @@ do_encode ()
                        mp2)
                                case "$MP2ENCODERSYNTAX" in
                                        twolame)
-                                       $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
-                                       ;;
+                                               $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER $MP2ENCODEROPTS "$IN" "$OUT"
+                                               ;;
                                        ffmpeg)
-                                       $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT" 
-                                       ;;
+                                               $RUN_COMMAND nice $EFFECTIVE_NICE $MP2ENCODER -i "$IN" $MP2ENCODEROPTS "$OUT" 
+                                               ;;
                                esac
                                ;;
                        aac)
@@ -1370,8 +1404,10 @@ do_encode ()
                                case "$AACENCODERSYNTAX" in
                                        faac)
                                                if [ "$DOTAG" = "y" ]; then
-                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS  --artist "$TRACKARTIST" --album "$DALBUM" \
-                                                       --title "$TRACKNAME" --track "${TRACKNUM:-$1}" --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
+                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS  \
+                                                                                --artist "$TRACKARTIST" --album "$DALBUM" \
+                                                                                --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
+                                                                                --year "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
                                                else 
                                                        $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"   
                                                fi
@@ -1381,16 +1417,20 @@ do_encode ()
                                                ;;
                                        fdkaac)      
                                                if [ "$DOTAG" = "y" ]; then
-                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS --artist "$TRACKARTIST" --album "$DALBUM" \
-                                                       --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
+                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS \
+                                                                                --artist "$TRACKARTIST" --album "$DALBUM" \
+                                                                                --title "$TRACKNAME" --track "$1" --genre "$CDGENRE" \
+                                                                                --date "$CDYEAR" --comment "$COMMENT" "$IN" -o "$OUT"
                                                else
                                                        $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER $AACENCODEROPTS "$IN" -o "$OUT"
                                                fi
                                                ;;
                                        qaac)
                                                if [ "$DOTAG" = "y" ]; then
-                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS  --artist "$TRACKARTIST" --album "$DALBUM" \
-                                                       --title "$TRACKNAME" --track "${TRACKNUM:-$1}" --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
+                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS \
+                                                                                --artist "$TRACKARTIST" --album "$DALBUM" \
+                                                                                --title "$TRACKNAME" --track "${TRACKNUM:-$1}" \
+                                                                                --date "$CDYEAR" --genre "$CDGENRE" --comment "$COMMENT" -o "$OUT" "$IN"
                                                else 
                                                        $RUN_COMMAND nice $EFFECTIVE_NICE $WINE $AACENCODER $AACENCODEROPTS -o "$OUT" "$IN"
                                                fi
@@ -1400,9 +1440,11 @@ do_encode ()
                                                ;;
                                        ffmpeg)
                                                if [ "$DOTAG" = "y" ]; then
-                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
-                                                       -metadata album="$DALBUM" -metadata title="$TRACKNAME" -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
-                                                       -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT" 
+                                                       $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN" \
+                                                                                $AACENCODEROPTS -metadata artist="$TRACKARTIST" \
+                                                                                -metadata album="$DALBUM" -metadata title="$TRACKNAME" \
+                                                                                -metadata track="${TRACKNUM:-$1}" -metadata date="$CDYEAR" \
+                                                                                -metadata genre="$CDGENRE" -metadata comment="$COMMENT" "$OUT" 
                                                else 
                                                        $RUN_COMMAND nice $EFFECTIVE_NICE $AACENCODER -i "$IN"  $AACENCODEROPTS "$OUT"
                                                fi
@@ -1436,7 +1478,8 @@ do_encode ()
 
 # do_preprocess [tracknumber]
 # variables used:
-# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
+# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX,
+# OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
 #do_preprocess ()
 #{
 #      IN="${ABCDETEMPDIR}/track$1.wav"
@@ -1477,7 +1520,8 @@ do_encode ()
 
 # do_postprocess [tracknumber]
 # variables used:
-# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
+# TRACKS, TRACKNAME, TRACKARTIST, DISTMP3, DISTMP3OPTS, {FOO}ENCODERSYNTAX, OUTPUTTYPE, ENCODEROPTS, 
+# DALBUM, DARTIST, ENCNICE, CDYEAR, CDGENRE, COMMENT
 #do_postprocess ()
 #{
 #      for POSTPROCESSFORMAT in $(echo $POSTPROCESSFORMATS | tr , \ )
@@ -1788,7 +1832,7 @@ do_playlist ()
                        for UTRACKNUM in $TRACKQUEUE
                        do
                                # Shares some code with do_move since the filenames have to match
-                               CDDBTRACKNUM=$(($UTRACKNUM - 1))
+                               CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
                                getcddbinfo TRACKNAME
                                splitvarious
                                TRACKFILE="$(mungetrackname "$TRACKNAME")"
@@ -1893,7 +1937,7 @@ abcde.cue2discid () {
 
        done
 
-       TRACKS="$i"
+       TRACKS=$i
        LEADOUT=$(( "$LEADOUT" + "$LEADIN" ))
 
        LENGTH=$(( "$LEADOUT"/75 - "$TRACK1"/75 ))
@@ -2020,7 +2064,7 @@ do_discid ()
                                                        TRACKS=${#OFFSETTIMES[@]}
                                                        unset OFFSETS
                                                        #echo "processing offsetimes ${OFFSETTIMES[@]}"
-                                                       for OFFSETTIME in "${OFFSETTIMES[@]}"; do
+                                                       for OFFSETTIME in ${OFFSETTIMES[@]}; do
                                                                OFFSETS="$OFFSETS $(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))"
                                                                #OFFSETS[${#OFFSETS[*]}]=$(( 10#${OFFSETTIME:0:2} * 4500 + 10#${OFFSETTIME:3:2} * 75 + 10#${OFFSETTIME:6:2} ))
                                                        done
@@ -2370,7 +2414,7 @@ do_cddbparse ()
                fi
        fi
        if [ ! "$ONETRACK" = "y" ]; then
-               for TRACK in $(f_seq_row 1 "$TRACKS")
+               for TRACK in $(f_seq_row 1 $TRACKS)
                do
                        echo "$TRACK": "$(grep -a ^TTITLE$(($TRACK - 1))= "${CDDBPARSEFILE}" | cut -f2- -d= | tr -d \\r\\n)"
                done
@@ -2424,19 +2468,14 @@ do_localcddb_read ()
                                                if [ ! "$INTERACTIVE" = "y" ]; then break ; fi
                                        } >> "${ABCDETEMPDIR}/cddblocalchoices"
                                done
-                               NUM_LINES=$(wc -l < "${ABCDETEMPDIR}/cddblocalchoices")
-                               if [ "$NUM_LINES" -ge $LINES ] && [ "$INTERACTIVE" = "y" ]; then
-                                       page "${ABCDETEMPDIR}/cddblocalchoices"
-                               else
-                                       # It's all going to fit in one page, cat it
-                                       cat "${ABCDETEMPDIR}/cddblocalchoices" >&2
-                               fi
+                               page "${ABCDETEMPDIR}/cddblocalchoices"
                                CDDBLOCALCHOICES=$( echo "$CDDBLOCALRESULTS" | wc -l )
                                # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
                                CDDBLOCALCHOICENUM=-1
                                if [ "$INTERACTIVE" = "y" ]; then
                                        while [ "$CDDBLOCALCHOICENUM" -lt 0 ] || [ "$CDDBLOCALCHOICENUM" -gt "$CDDBLOCALCHOICES" ]; do
-                                               echo -n "Locally cached CDDB entries found. Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
+                                               echo "Locally cached CDDB entries found." >&2
+                                               echo -n "Which one would you like to use (0 for none)? [0-$CDDBLOCALCHOICES]: " >&2
                                                read CDDBLOCALCHOICE
                                                [ x"$CDDBLOCALCHOICE" = "x" ] && CDDBLOCALCHOICE="1"
                                                # FIXME # Introduce diff's
@@ -2735,7 +2774,9 @@ do_cddb_read ()
                        # One exact match, retrieve it
                        # 200 [section] [discid] [artist] / [title]
                        NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
-                       $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
+                       $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
+                                         $(cut -f2,3 -d' ' "${SOURCE_WORKDIR}/cddbquery") \
+                                         > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
                        cat "${SOURCE_WORKDIR}/cddbquery" | cut -f2- -d' ' > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
                        echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
                        echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
@@ -2756,7 +2797,9 @@ do_cddb_read ()
                                do
                                        NUM_CDDB_MATCHES=$(($NUM_CDDB_MATCHES + 1))
                                        if checkstatus "cddb-read-${NUM_CDDB_MATCHES}-complete"; then :; else
-                                               $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" $(echo "$DISCINFO" | cut -f1,2 -d' ') > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
+                                               $CDDBTOOL read "$CDDBURL" "$CDDBPROTO" "$CDDBUSER" "$CDDBHOST" \
+                                                                 $(echo "$DISCINFO" | cut -f1,2 -d' ') \
+                                                                 > "${SOURCE_WORKDIR}/cddbread.${NUM_CDDB_MATCHES}"
                                                echo "$DISCINFO" > "${SOURCE_WORKDIR}/cddbquery.${NUM_CDDB_MATCHES}"
                                                echo "cddb" > "${SOURCE_WORKDIR}/datasource.${NUM_CDDB_MATCHES}"
                                                echo "cddb-read-${NUM_CDDB_MATCHES}-complete" >> "${ABCDETEMPDIR}/status"
@@ -2797,7 +2840,6 @@ do_cddbedit ()
                # or when we are using it but we could not find a proper match
                if [ "$CDDBUSELOCAL" = "y" ] && [ "$CDDBLOCALSTATUS" = "notfound" ] || [ ! "$CDDBUSELOCAL" = "y" ]; then
                        # Display the ${ABCDETEMPDIR}/cddbchoices file created above
-                       # Pick a pager so that if the tracks overflow the screen the user can still view everything
                        if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
                                CHOICE=$(checkstatus cddb-choice)
                                if [ -n "$CHOICE" ] ; then
@@ -2811,15 +2853,7 @@ do_cddbedit ()
                                                ;;
                                        esac
                                else
-                                       # The user has a choice to make, display the info in a pager if necessary
-                                       NUM_LINES=$(wc -l < "${ABCDETEMPDIR}/cddbchoices")
-                                       if [ "$NUM_LINES" -ge $LINES ]; then
-                                               page "${ABCDETEMPDIR}/cddbchoices"
-                                       else
-                                               # It's all going to fit in one page, cat it
-                                               cat "${ABCDETEMPDIR}/cddbchoices" >&2
-                                       fi
-
+                                       page "${ABCDETEMPDIR}/cddbchoices"
                                        CDDBCHOICENUM=""
                                        # Setting the choice to an impossible integer to avoid errors in the numeric comparisons
                                        CDCHOICENUM=-1
@@ -2835,23 +2869,24 @@ do_cddbedit ()
                                                                if [ "$PARSECHOICE1" -lt 1 ] || [ "$PARSECHOICE1" -gt "$NUM_CDDB_MATCHES" ] || \
                                                                   [ "$PARSECHOICE2" -lt 1 ] || [ "$PARSECHOICE2" -gt "$NUM_CDDB_MATCHES" ] || \
                                                                   [ "$PARSECHOICE1" -eq "$PARSECHOICE2" ]; then
-                                                                       echo "Invalid diff range. Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
+                                                                       echo "Invalid diff range." >&2
+                                                                       echo "Please select two comma-separated numbers between 1 and $NUM_CDDB_MATCHES" >&2
                                                                else
                                                                        # We parse the 2 choices to diff, store them in temporary files and diff them.
                                                                        for PARSECHOICE in $(echo $CDDBCHOICE | tr , \ ); do
-                                                                               do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
+                                                                               do_cddbparse "${ABCDETEMPDIR}/cddbread.$PARSECHOICE" \
+                                                                                                        > "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE"
                                                                        done
-                                                                       echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." > "${ABCDETEMPDIR}/cddbread.diff"
-                                                                       $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" >> "${ABCDETEMPDIR}/cddbread.diff"
-                                                                       NUM_LINES=$(wc -l < "${ABCDETEMPDIR}/cddbread.diff")
-                                                                       if [ "$NUM_LINES" -ge $LINES ]; then
-                                                                               page "${ABCDETEMPDIR}/cddbread.diff"
-                                                                       else
-                                                                               cat "${ABCDETEMPDIR}/cddbread.diff" >&2
-                                                                       fi
+                                                                       echo "Showing diff between choices $PARSECHOICE1 and $PARSECHOICE2..." \
+                                                                                > "${ABCDETEMPDIR}/cddbread.diff"
+                                                                       $DIFF $DIFFOPTS "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE1" \
+                                                                                 "${ABCDETEMPDIR}/cddbread.parsechoice.$PARSECHOICE2" \
+                                                                                 >> "${ABCDETEMPDIR}/cddbread.diff"
+                                                                       page "${ABCDETEMPDIR}/cddbread.diff"
                                                                fi
                                                        else
-                                                               echo "The diff program was not found in your path. Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
+                                                               echo "The diff program was not found in your path." >&2
+                                                               echo "Please choose a number between 0 and $NUM_CDDB_MATCHES." >&2
                                                        fi
                                                elif echo $CDDBCHOICE | grep -E "[[:space:]]*[[:digit:]]+[[:space:]]*" > /dev/null 2>&1 ; then
                                                        # Make sure we get a valid choice
@@ -2870,8 +2905,8 @@ do_cddbedit ()
                                                ATITLE=$(grep -a ^DTITLE= "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM" | cut -f2- -d= | tr -d \\r\\n)
                                                SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$CDCHOICENUM")
                                                echo "Selected: #$CDCHOICENUM ($SOURCE) ($ATITLE)" >&2
-                                               do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
                                        fi
+                                       do_cddbparse "${ABCDETEMPDIR}/cddbread.$CDCHOICENUM"
                                        echo "cddb-choice=$CDCHOICENUM" >> "${ABCDETEMPDIR}/status"
                                fi
                        fi
@@ -2879,7 +2914,6 @@ do_cddbedit ()
                        # We need some code to show the selected option when local repository is selected and we have found a match
                        vecho "Using cached CDDB match..." >&2
                        # Display the ${ABCDETEMPDIR}/cddbchoices file created above
-                       # Pick a pager so that if the tracks overflow the screen the user can still view everything
                        if [ -r "${ABCDETEMPDIR}/cddbchoices" ]; then
                                CHOICE=$(checkstatus cddb-choice)
                                if [ "$USELOCALRESP" = "y" ]; then :; else
@@ -3220,7 +3254,8 @@ do_getalbumart()
                                rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE.tmp"
                        else
                                rm -f "${ABCDETEMPDIR}/$ALBUMARTFILE"
-                               vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE without ImageMagick convert" >&2
+                               vecho "sorry, cannot convert $ALBUMARTURLTYPE to $ALBUMARTTYPE" >&2
+                               vecho "without ImageMagick convert" >&2
                        fi
                fi
        fi
@@ -3416,8 +3451,8 @@ do_cdread ()
                # the user said
                # We need the first and last track for cdda2wav/icedax
                FIRSTTRACK=$2
-               LASTTRACK=$(($3 + 0))
-               UTRACKNUM="$FIRSTTRACK"
+               LASTTRACK=$(expr $3 + 0)
+               UTRACKNUM=$FIRSTTRACK
                case "$CDROMREADERSYNTAX" in
                        flac) READTRACKNUMS="-" ;;
                        cdparanoia|libcdio)
@@ -3434,7 +3469,7 @@ do_cdread ()
        else
                UTRACKNUM=$1
        fi
-       CDDBTRACKNUM=$(($UTRACKNUM - 1))
+       CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
        if [ "$USEPIPES" = "y" ]; then
                TEMPARG="PIPERIPPER_$CDROMREADERSYNTAX"
                FILEARG="$( eval echo "\$$TEMPARG" )"
@@ -3466,7 +3501,7 @@ do_cdread ()
                ### FIXME ### Shall we just use -o $FILEARG ??
                flac)
                        # Avoid problems with math expressions by unpadding the given UTRACKNUM
-                       STRIPTRACKNUM=$(( $UTRACKNUM + 0 ))
+                       STRIPTRACKNUM=$(expr $UTRACKNUM + 0 )
                        nice $READNICE $FLAC -d -f --cue="${READTRACKNUMS:-$STRIPTRACKNUM.1-$(($STRIPTRACKNUM + 1)).0}" "$FILEARG" "$CDROM" ;;
                cdparanoia|libcdio)
                        if [ "$USEPIPES" = "y" ]; then
@@ -3511,7 +3546,7 @@ do_cdread ()
                ;;
                cddafs)
                        # Find the track's mounted path
-                       REALTRACKNUM=$(($UTRACKNUM + 0))
+                       REALTRACKNUM=$(expr $UTRACKNUM + 0) # Unpad
                        FILEPATH=$(mount | grep "$CDROM on" | sed 's/^[^ ]* on \(.*\) (.*/\1/')
                        FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
                        # If the file exists, copy it
@@ -4044,14 +4079,20 @@ case "$EXTRAVERBOSE" in
 esac
 
 # Parse command line options
-while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pP:Q:r:s:S:t:T:UvVxX:w:W:z opt ; do
+while getopts 1a:bBc:C:d:DefgGhj:klLmMnNo:pPQ:r:s:S:t:T:UvVxX:w:W:z opt ; do
        case "$opt" in
                1) ONETRACK=y ;;
                a) ACTIONS="$OPTARG" ;;
                A) EXPACTIONS="$OPTARG" ;;
                b) BATCHNORM=y ;;
                B) GETALBUMART=y ; EMBEDALBUMART=y ;;
-               c) if [ -e "$OPTARG" ] ; then . "$OPTARG" ; else log error "config file \"$OPTARG\" cannot be found." ; exit 1 ; fi ;;
+               c) if [ -e "$OPTARG" ]; then
+                          . "$OPTARG"
+                  else
+                          log error "config file \"$OPTARG\" cannot be found."
+                          exit 1
+                  fi
+                  ;;
                C) CDDBDISCID="$( echo "${OPTARG#abcde.}" | tr -d /)" ;;
                d) CDROM="$OPTARG" ;;
                D) set -x ;;
@@ -4777,7 +4818,8 @@ if [ X"$OGGOUTPUTCONTAINER" = "Xogg" ] && [ X"$FLACOUTPUTCONTAINER" = "Xogg" ];
        exit 1
        OGGOUTPUTCONTAINER=ogg.ogg
        FLACOUTPUTCONTAINER=flac.ogg
-       vecho warning "modified file endings due to conflicting transport layers in Ogg/Vorbis and Ogg/FLAC"
+       vecho warning "modified file endings due to conflicting transport"
+       vecho warning "layers in Ogg/Vorbis and Ogg/FLAC"
 fi
 
 # Clean up nice options (either use '-n NICELEVEL or -NICELEVEL')
@@ -4970,8 +5012,19 @@ HTTPGET="$HTTPGET $HTTPGETOPTS"
 # Hey, for grins, as of 2016-08-30 this is now line 4814! -GR
 
 # Export needed things so they can be read in this subshell
-export CDDBTOOL ABCDETEMPDIR TRACKQUEUE LOWDISK EJECTCD EJECT EJECTOPTS
-export CDROM CDDBDATA REMOTEHOSTS MAXPROCS HTTPGET MD5SUM
+export CDDBTOOL        # Path and options for the tool to query CDDB
+export ABCDETEMPDIR    # Path to the tmpdir for this rip
+export TRACKQUEUE      # 0-padded list of tracks to be processed
+export LOWDISK         # Are we using the low-diskspace algorithm?
+export EJECTCD         # Should we eject the CD when we're finished ripping?
+export EJECT           # The commend to use to eject the CD, if we have one
+export EJECTOPTS       # Options to that command
+export CDROM           # Device path for the CD device
+export CDDBDATA        # The filename we're using for CD lookup data
+export REMOTEHOSTS     # List of remote hosts for parallel encoding, if given
+export MAXPROCS        # The number of *local* encodes to do in parallel
+export HTTPGET         # Program to use to grab files via http
+export MD5SUM          # Program to calculate MD5 checksums
 
 if [ "$DOREAD" = "y" ]; then
        # User-definable function to set some things. Use it for
@@ -5041,7 +5094,7 @@ if [ "$DOCDDB" = "y" ]; then
                                # List out disc title/author and contents of template
                                echo ---- Unknown Artist / Unknown Album ---- >> "${ABCDETEMPDIR}/cddbchoices"
                                UNKNOWNDISK=y
-                               for TRACK in $(f_seq_row 1 "$TRACKS")
+                               for TRACK in $(f_seq_row 1 $TRACKS)
                                do
                                        echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.0" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
                                done
@@ -5071,11 +5124,11 @@ if [ "$DOCDDB" = "y" ]; then
                                        ATITLE=$(grep -a -e '^DTITLE=' "${ABCDETEMPDIR}/cddbread.$X" | cut -c8- | tr -d \\r\\n)
                                        SOURCE=$(cat "${ABCDETEMPDIR}/datasource.$X")
                                        echo "#$X ($SOURCE): ---- ${ATITLE} ----" >> "${ABCDETEMPDIR}/cddbchoices"
-                                        for TRACK in $(f_seq_row 1 "$TRACKS")
-                                        do
-                                                echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
-                                        done
-                                        echo >> "${ABCDETEMPDIR}/cddbchoices"
+                    for TRACK in $(f_seq_row 1 $TRACKS)
+                                       do
+                        echo "$TRACK:" "$(grep -a ^TTITLE$(($TRACK - 1))= "${ABCDETEMPDIR}/cddbread.$X" | cut -f2- -d= | tr -d \\r\\n)" >> "${ABCDETEMPDIR}/cddbchoices"
+                                       done
+                    echo >> "${ABCDETEMPDIR}/cddbchoices"
                                done
                        fi
                fi
@@ -5137,14 +5190,14 @@ if [ "$LOWDISK" = "y" ] || [ "$ONETRACK" = "y" ]; then
 fi
 
 if [ "$ONETRACK" = "y" ]; then
-       TRACKS="$FIRSTTRACK"
+       TRACKS=$FIRSTTRACK
        if [ "$USEPIPES" = "y" ]; then
                if checkstatus "readencodetrack-$FIRSTTRACK"; then :; else
-                       do_cdread onetrack "$FIRSTTRACK" "$LASTTRACK" | do_encode "$FIRSTTRACK" %local0% > /dev/null 2>&1
+                       do_cdread onetrack $FIRSTTRACK $LASTTRACK | do_encode $FIRSTTRACK %local0% > /dev/null 2>&1
                fi
        else
                if checkstatus "readtrack-$FIRSTTRACK"; then :; else
-                       do_cdread onetrack "$FIRSTTRACK" "$LASTTRACK"
+                       do_cdread onetrack $FIRSTTRACK $LASTTRACK
                fi
        fi
 else
@@ -5154,11 +5207,11 @@ else
                        if [ "$USEPIPES" = "y" ]; then
                                if checkstatus "readencodetrack-$UTRACKNUM"; then :; else
                                        # Read, pipe, shut up!
-                                       do_cdread "$UTRACKNUM" | do_encode "$UTRACKNUM" %local0% > /dev/null 2>&1
+                                       do_cdread $UTRACKNUM | do_encode $UTRACKNUM %local0% > /dev/null 2>&1
                                fi
                        else
                                if checkstatus "readtrack-$UTRACKNUM"; then :; else
-                                       do_cdread "$UTRACKNUM"
+                                       do_cdread $UTRACKNUM
                                fi
                                if [ "$?" != "0" ]; then
                                        # CD read failed - don't give the goahead to
@@ -5293,7 +5346,7 @@ fi
 # Figure out where each track is going to be encoded
 ENCODELOCATIONS="$(echo "$REMOTEHOSTS" | tr , ' ')"
 if [ "$MAXPROCS" != "0" ]; then
-       for NUM in $(f_seq_row 1 "$MAXPROCS")
+       for NUM in $(f_seq_row 1 $MAXPROCS)
        do
                ENCODELOCATIONS="$ENCODELOCATIONS %local$NUM%"
        done
@@ -5355,7 +5408,7 @@ do
                        splitvarious
                else
                        TRACKNUM="$UTRACKNUM"
-                       CDDBTRACKNUM=$(($UTRACKNUM - 1))
+                       CDDBTRACKNUM=$(expr $UTRACKNUM - 1) # Unpad
                        getcddbinfo TRACKNAME
                        splitvarious
                fi