Bash脚本比较不起作用

时间:2013-11-23 18:59:26

标签: bash

我正在处理一个bash脚本,由于某种原因if语句总是成真。如果我运行以下应用程序并在提示符下输入yes并按Enter键,这里打印出来的内容:

The code will be checked out in the location the file is in, is this ok? (yes or no)
yes
yes
Stopping app

这是我的代码的样子。我在这里错过了什么吗?

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 个答案:

答案 0 :(得分:3)

问题在于-eq-eq用于数字比较。请改用=, 所以

[[ $answer = "no" ]]

而不是

[[ $answer -eq "no" ]]