shell 字符串比较,该怎么处理
shell 字符串比较#!/bin/bashaphbphif[$a $b]thenecho successfi这个代码有问题 。。。提示如
shell 字符串比较
#!/bin/bash
a="ph"
b="ph"
if["$a" = "$b"];then
echo "success"
fi
这个代码有问题 。。。提示如下:
./equ.sh: line 4: syntax error near unexpected token `then'
./equ.sh: line 4: `if["hi" = "hi"];then'
[解决办法]
#!/bin/bash
a="ph"
b="ph"
if["$a" == "$b"];then
echo "success"
fi
[解决办法]楼主错误的原因是因为if["$a" = "$b"];then中少了空格。不是==的问题。
if [ "$a" = "$b" ]; then这样就行了。