if lsusb | grep "Spreadtrum" > /dev/null 2>&1
thenecho " success"
else
echo " fail"
fi
lsusb | grep "Spreadtrum" > /dev/null 2>&1
if [ "$?" -eq "0" ];then
echo "success"
else
echo "fail"
fi
以上2种方式意思相同,故可使用第1种较为简洁
主要原因是
BJS\lisa.liu@lisaliuubtpc:~/bin$ lsusb | grep "Spreadtrum"
Bus 002 Device 017: ID 1782:5d04 Spreadtrum Communications Inc.
输出有很多域,故不能直接使用
if [ -n `lsusb | grep "Spreadtrum"` ]then
echo "success"
else
echo "fail"
fi
否则会出现错误提示: bash: [: too many arguments
如果仅有一个域输出,则可以使用最后一种格式,但需要改写
if [ -n `lsusb | grep "Spreadtrum" | awk '{ print $7 }'` ]
then
echo "success"
else
echo "fail"
fi