For user general input in variable we use command read:
#!/bin/bash
read -p "Enter first number:" num1
read -p "Enter second number:" num2
if [ num1 -eq num2 ]
then
echo "Numbers are equal"
else
if [ $num1 -lt $num2 ]
then
echo "Second number is larger"
else
echo "First number is larger"
fi
fi
For entering exact expected word (example Yes or No) we use command select:
#!/bin/bash
echo "Do you want continue?"
select inp in "yes" "no"
do
case $inp in
yes ) echo "You want to continue"
break
;;
no ) echo "You want to exit"
break
;;
esac
done
No comments:
Post a Comment