- 对变量赋值时,等号两边不能有空格
- 引用变量时,最好在其两边加上双引号,即 "$var",以处理在var中有空格及var为空的情况
$ string="hello world"
$ func () { echo $1; }
$ func $string
hello
$ func "$string"
hello world
$ string=""
$ str="hello"
$ [ $string = $str ] && echo "equal" || echo "unequal"
bash: [: =: unary operator expected
unequal
$ [ "$string" = $str ] && echo "equal" || echo "unequal"
unequal
待续
转载请注明出处 http://fornote.blogspot.com
没有评论:
发表评论