shell中if后面的判断语句用不用[]括起来有什么区别?
洛阳山 2016-10-19 02:23:11 1 #!/bin/bash
2
3 SUCCESS=0
4 FAILURE=-1
5
6 isdigit()
7 {
8 [ $# -eq 1 ]||return $FAILURE
9
10 case $1 in
11 *[!0-9]*|" ") return $FAILURE;;
12 *) return $SUCCESS;;
13 esac
14 }
15
16 number=78
17 number2=98
18 #isdigit $number
19 #echo $?
20 #if isdigit "$number" && isdigit "$number2"
21 if [ isdigit "$number" ]
22 then
23 echo "yes"
24 else
25 echo "error"
26 fi
代码第21行会报错,用20行的可以