0

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

1 Answer 1

3

The problem is with the -eq. -eq is for numeric comparisons. Use = instead, so

[[ $answer = "no" ]]

instead of

[[ $answer -eq "no" ]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.