So the problem is i am not getting the desired output. Need some help in the problem statement as i am a newbie to the BashScript!!
Asked
Active
Viewed 1,071 times
-3
-
Welcome to stackoverflow, you have to show us by posting samples into your post like what is working and what is not. If you say something is not working without showing us, we can't help on it, please do the needful in your post. – RavinderSingh13 Feb 03 '18 at 07:10
-
1You should be using `=`. `-eq` is for comparing numbers, not strings. – Barmar Feb 03 '18 at 07:43
-
See https://stackoverflow.com/questions/47475445/why-does-eq-show-non-numerical-strings-as-equal-in-bash – Barmar Feb 03 '18 at 07:45
-
Since `[[` is for pattern matching, try: `if [[ $input = [Yy] ]]` – cdarke Feb 03 '18 at 07:50
-
Thanks it's done!! – Manoj Kumar Feb 03 '18 at 08:38
1 Answers
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.

paxdiablo
- 854,327
- 234
- 1,573
- 1,953