Bash条件循环问题Y或y ==>是N或n ==> NO

时间:2018-02-03 07:00:53

标签: bash shell if-statement syntax scripting

ICode

Input & Output

所以问题是我没有得到所需的输出。在问题陈述中需要一些帮助,因为我是BashScript的新手!!

1 个答案:

答案 0 :(得分:1)

-eq is for numeric comparisons and all of the strings YES, Y, N and NO evaluate to zero. Hence they'll all match each other.

You should be using = rather than -eq.

However, you can also use regular expressions in bash with something like:

[[ $input =~ [Yy] ]]

That seems much more readable to me.