Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled.

 
#!/bin/sh
echo " Enter your choice  to continue y/Y  OR n/N to quit "
read A
if [ "$A" = "y" || "$A" = "Y" ]
then
echo " user requested to continue "
##some commands
else
echo " User requested to cancel"
exit 1
fi
exit 0

 

above code is throwing error, please suggest

Correction:-

if [[ "$A" = "y" || "$A" = "Y" ]]

i tried its throwing error, marked in red

#!/bin/sh
echo " Enter your choice  to continue y/Y  OR n/N to quit "
read A
if [ [  "$A" = "y" || "$A" = "Y" ] ]
then
echo " user requested to continue "
##some commands
else
echo " User requested to cancel"
exit 1
fi
exit 0
 

i passed parameter as Y, it is throwing below error

 
[ : 14 : missing ]

I did not put any spaces between the square brackets! Remove the spaces and re-try.

You need two "==" in your if statements. A single "=" assigns whatever is after to whatever is before. Double "==" means "is equal to".

if [[ "$A" == "y" || "$A" == "Y" ]]

---------- Post updated at 12:45 PM ---------- Previous update was at 12:43 PM ----------

Actually, I guess it will work either way but two "==" would be a good habit to get into.

[[ .. ]] is not POSIX syntax and as such should not be used with #!/bin/sh The correct syntax would be:

if [ "$A" = "y" ] || [ "$A" = "Y" ]
then

--
The correct bash/ksh syntax would be

if [[ $A == "y" || $A == "Y" ]]
then

or

if [[ $A == [yY] ]]
then 

try this
if [ "$A" -eq "y" || "$A" -eq "Y" ]
and check spaces

That is wrong. Operator eq is used for numeric comparison, not for string comparison.