#!/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