Reputation: 3501
I am working on a bash script and for some reason the if statement is always coming true. If I run the following app and at the prompt I type yes and hit enter, here is what prints out:
The code will be checked out in the location the file is in, is this ok? (yes or no)
yes
yes
Stopping app
Here is what my code looks like. Am I missing something here?
echo "The code will be checked out in the location the file is in, is this ok? (yes or no)"
read answer
echo $answer
if [[ $answer -eq "no" ]] ; then
echo "Stopping app"
exit 1
fi
Upvotes: 0
Views: 38
Reputation: 23364
The problem is with the -eq
. -eq
is for numeric comparisons. Use =
instead,
so
[[ $answer = "no" ]]
instead of
[[ $answer -eq "no" ]]
Upvotes: 3