-1
#!/bin/bash
echo "------------"
echo "Welcome Page"
echo "------------"
a="mango"
while true
do
echo "Type mango for exit"
read data
if [ $data -ne $a]; then
echo "Wrong choice"
exit 1
fi

done

The output is:

------------
Welcome Page
------------
Type mango for exit
mango
while.sh: line 10: [: missing `]'
Type mango for exit
Pierre François
  • 5,850
  • 1
  • 17
  • 38
Hack-Z
  • 47
  • 7

1 Answers1

2

It's always good to put quotes around string variables to avoid spaces/newline conflicts.

#!/bin/bash

echo "------------"
echo "Welcome Page"
echo "------------"
a="mango"
while true
do
    echo "Type mango for exit"
    read data
    echo $data
    if [ "$data" != "$a" ]; then
        echo "Wrong choice"
        exit 1
    fi
done
thirdeye
  • 150
  • 7