#!/bin/bash
check_input(){
read -p "请输入,要想退出请输入q: " input
[ -z $input ] && {
echo "你输入的是空"
continue
}
[ "$input" == "q" ] && exit 1
result=`echo "$input*1"|bc`
if [ $? -ne 0 ];then
echo "输入的[$input]是字符串"
else
if [ $result -eq 0 ];then
echo "输入的[$input]是字符串"
else
echo "你输入的[$input]是数字"
fi
fi
}
main(){
while true
do
check_input
done
}
main
]# bash check-input-type.sh
请输入,要想退出请输入q: !dadsaf
你输入的[!dadsaf]是数字
请输入,要想退出请输入q: 34323
你输入的[34323]是数字
请输入,要想退出请输入q: aaf
输入的[aaf]是字符串
请输入,要想退出请输入q: q