On Mon, 7 Sep 2015 11:15:32 +0100 Steve Engledow steve@offend.me.uk wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 07/09, Chris Walker wrote:
for FILE in *.mp3 do bname=$(basename "$FILE") extension="${bname##*.}" filenamewoext="${bname%.*}" imagefile="${filenamewoext}.png" echo adding cover image ... eyeD3 --add-image $imagefile:FRONT_COVER:Picture "$FILE"
echo Stripping any version 1 tags id3v2 --delete-v1 "$FILE" # Now for a tidy up and delete the original image file # search and add image img=$(id3v2 -l "$FILE" | grep -i "APIC") if $img =""; then echo "Adding the image failed" exit 1 else rm -f $imagefile fi
done
The problem comes in the tidy up section. I don't want to delete the image file if adding it has failed but even though I'm getting an error "mp3image.sh: line 47: APIC: command not found", the image is still being deleted.
You can use the special bash variable `$?` to get the return code of the last command that run.
This means you can do something like:
img=$(id3v2 -l "$FILE" | grep -i "APIC") if [ $? -ne 0 ]; then # clean up from failure fi
Steve
Thanks Steve, and also to Thomas for his suggestion.