在我的 bash 脚本中,我尝试使用等号 (=) 运算符作为 IF 语句的输入,可以这样做吗?
echo "Plese enter an operator as shown in the brackets (-)subtract, (*)Multiply, (+)Add, (/)divide, quit(=)?"
read operator
..........
if [[ $operator == '=' ]]; then
'do something'
fi
在我的 bash 脚本中,我尝试使用等号 (=) 运算符作为 IF 语句的输入,可以这样做吗?
echo "Plese enter an operator as shown in the brackets (-)subtract, (*)Multiply, (+)Add, (/)divide, quit(=)?"
read operator
..........
if [[ $operator == '=' ]]; then
'do something'
fi
我不明白你为什么不能这样做。
> operator==
> echo $operator
=
> if [[ $operator == '=' ]]; then echo 'ok'; fi;
ok
试试这个shell.sh
:
#!/bin/sh
EQUAL="=" #this is our operator
echo "Please enter operator"
read operator
if [ $operator = $EQUAL ]; then
echo "Entered = "
else
echo "Not = entered"
fi
执行:
:~$ sh shell.sh
Please enter operator
=
Entered =
:~$ sh shell.sh
Please enter operator
-
Not = entered
:~$