#!/bin/bash
#judge image file type
#判斷是否只有一個參數
if [ $# != 1 ]
then
echo "parameter error"
else
## 讀取前3個字節與前4個字節對應的16進制
len3=`xxd -p -l 3 $1`
len4=`xxd -p -l 4 $1`
if [ $len3 == "ffd8ff" ]
then
echo "The type is jpg"
elif [ $len4 == "89504e47" ]
then
echo "The type is png"
elif [ $len4 == "47494638" ]
then
echo "The type is gif"
else
echo "The type is others"
fi
fi