vendredi 21 décembre 2018

What would be the best way to test if a file has one of several acceptable file extensions?

I have the following code to test if the file held in $arg is not one of several file extensions. In an effort to learn I want to know if there is a more correct, more compact way to do this.

if ! [[ -f "$arg" && ( $arg = *.mkv || $arg = *.mp4 || $arg = *.mp3 || $arg = *.flac || $arg = *.avi) ]] ; then
    echo -e "\"$arg\" is an invalid directory, filename or file format\n"
fi

Aucun commentaire:

Enregistrer un commentaire