function check(){ local a="$1" printf "%d" "$a" &>/dev/null && echo "integer" && return printf "%d" "$(echo $a|sed 's/^[+-]?0+//')" &>/dev/null && echo "integer" && return printf "%f" "$a" &>/dev/null && echo "number" && return [ ${#a} -eq 1 ] && echo "char" && return echo "string" } echo $(check "xx") 输出: string