If would like to install an application or software using Shell script and prompt the user choices either Yes or No or Cancel type question to proceed to the next step with the condition,
Method 1:
Can use the "read command with -p option, one line is read from the standard input. -p or prompt, The prompt is displayed only if the input is coming from a terminal.
while true; do
read -p "Do you want to Install the Package?" yn
case $yn in
[Yy]* ) make && make install; break;;
[Nn]* ) exit;;
* ) echo "Enter valid input: Yy or Nn";;
esac
done
Method 2:
Another method is using the select command, the sample code lines are,
echo "Do you want to Install the Package?"
select yn in "Yes" "No"; do
case $yn in
Yes ) make && make install; break;;
No ) exit;;
esac
done
Ref: http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Conditional-Constructs
Comments (0)