当前位置: 技术问答>linux和unix
一个关于shell的问题,麻烦帮忙解释一下
来源: 互联网 发布时间:2016-04-20
本文导语: str1="I am owen" str2="me too" if [ $str1 = $str2 ]; then print "str1 is longer than str2" else print "str1 is less then str2" fi 运行程序后,报告如下错误 ./if.sh: line 3: [: too many arguments ./if.sh: line 6: print: command not found ...
str1="I am owen"
str2="me too"
if [ $str1 = $str2 ]; then
print "str1 is longer than str2"
else
print "str1 is less then str2"
fi
运行程序后,报告如下错误
./if.sh: line 3: [: too many arguments
./if.sh: line 6: print: command not found
|
shell在做变量替换时将把
if [ $str1 = $str2 ]; then
替换为
if [ I am owen = me too ]; then
I am owen被视为3个字符串而不是一个整体,所以才会报too many arguments的错
正确用法:
if [ "$str1" = "$str2" ]; then
if [ $str1 = $str2 ]; then
替换为
if [ I am owen = me too ]; then
I am owen被视为3个字符串而不是一个整体,所以才会报too many arguments的错
正确用法:
if [ "$str1" = "$str2" ]; then