Skip to content

Instantly share code, notes, and snippets.

@labbots
Created December 23, 2016 13:20
Show Gist options
  • Save labbots/3e78c00967a130e21982a1aaaba96eca to your computer and use it in GitHub Desktop.
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
#!/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