当前位置: 技术问答>linux和unix
shell学习时一个小问题
来源: 互联网 发布时间:2017-05-06
本文导语: 请各位大虾看看下面这段shell程序,为什么不能实现输出else分支的内容: #!/bin/bash read -p 'input your name here:' NAME echo $NAME if [ $NAME="otto" ]; then echo "you is otto" else echo "unknown what you name" fi...
请各位大虾看看下面这段shell程序,为什么不能实现输出else分支的内容:
#!/bin/bash
read -p 'input your name here:' NAME
echo $NAME
if [ $NAME="otto" ]; then
echo "you is otto"
else
echo "unknown what you name"
fi
我输入aaa,总是输出you is otto.
不能输出unknown what you name
#!/bin/bash
read -p 'input your name here:' NAME
echo $NAME
if [ $NAME="otto" ]; then
echo "you is otto"
else
echo "unknown what you name"
fi
我输入aaa,总是输出you is otto.
不能输出unknown what you name
|
$NAME="otto"你这是赋值语句,永真。
你要改成
你要改成
$NAME = "otto"等号两边都要用空格。