Reputation: 17
Would someone mind giving me a hand with the following IF Statement?
read -e -p "Would you like to reboot now?: " -i " " REBOOT
if $REBOOT = 'yes' ; then
echo 'System will now reboot'
shutdown -r now
else $REBOOT != 'yes'
echo 'You have chosen to reboot later'
fi
If I enter 'yes' I get the following as an endless result
= yes
= yes
= yes
...
= yes
And if I enter 'no' I get the following:
./test.sh: line 7: no: command not found
./test.sh: line 10: no: command not found
You have chosen to reboot later
Any ideas?
Upvotes: 0
Views: 129
Reputation: 1198
The output you're getting is the same as if you typed:
yes = 'yes'
To denote a comparison, you should use brackets on the if. It should be:
if [ $REBOOT = 'yes' ] ; then
plus you have a second condition on the else without another if. You don't need it anyway
Total code should be:
if [ $REBOOT = 'yes' ] ; then
echo 'System will now reboot'
shutdown -r now
else
echo 'You have chosen to reboot later'
fi
Upvotes: 2