当前位置: 技术问答>linux和unix
shell 字符串比较
来源: 互联网 发布时间:2017-03-21
本文导语: #!/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' | 楼主错误的原因是因为if["$a" = ...
#!/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'
|
楼主错误的原因是因为if["$a" = "$b"];then中少了空格。不是==的问题。
if [ "$a" = "$b" ]; then这样就行了。
if [ "$a" = "$b" ]; then这样就行了。
|
#!/bin/bash
a="ph"
b="ph"
if["$a" == "$b"];then
echo "success"
fi