Reputation: 95
In my bash script i am trying to using the equals (=) operator as input for an IF statement, can this be done?
echo "Plese enter an operator as shown in the brackets (-)subtract, (*)Multiply, (+)Add, (/)divide, quit(=)?"
read operator
..........
if [[ $operator == '=' ]]; then
'do something'
fi
Upvotes: 2
Views: 652
Reputation: 58281
Try this 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
Execution:
:~$ sh shell.sh
Please enter operator
=
Entered =
:~$ sh shell.sh
Please enter operator
-
Not = entered
:~$
Upvotes: 1
Reputation: 9216
I don't understand why you could not be able to do this.
> operator==
> echo $operator
=
> if [[ $operator == '=' ]]; then echo 'ok'; fi;
ok
Upvotes: 2