Reputation: 2779
Ok, so I'm trying to run a script where if the user enters y
or Y
, then the output is YES
but if the user inputs n
or N
then the output is NO
, this is what I have so far:
read character
if (( ("$character") == "y" )) || (( ("$character" == "Y") )); then
echo "YES"
else
echo "NO"
fi
When I run this code I get YES
successfully but inputting n
just results in YES
anyway.
I have no idea what I'm doing wrong and any I'd love some input.
Thanks in advance!
Upvotes: 2
Views: 79
Reputation: 784918
((...))
is used for math calculations. You can use [[...]]
in BASH like this:
read character
if [[ "$character" == [yY] ]]; then
echo "YES"
else
echo "NO"
fi
Also I have combined 2 conditions into one using [yY]
glob pattern.
Upvotes: 4