Created
December 23, 2016 13:20
-
-
Save labbots/3e78c00967a130e21982a1aaaba96eca to your computer and use it in GitHub Desktop.
Get mime-type of a file based on extension if exists or by using file command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE=$(basename $1) | |
FILENAME="${FILE%.*}" | |
EXTENSION="${FILE##*.}" | |
echo "$FILE" | |
echo "$FILENAME" | |
echo "$EXTENSION" | |
if [ "$FILENAME" == "$EXTENSION" ] | |
then | |
MIMETYPE=`file --brief --mime-type "$1"` | |
else | |
MIMETYPE=`mimetype --output-format %m "$1"` | |
fi | |
echo "$MIMETYPE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment