Welcome to Server Circle. It's a friendly site and all levels of experience are welcome. Be aware that we use cookies for your login.
Server Circle - Ask questions about Servers and get answers from experts.
Beta (0.90 sec)
User input from BASH script

How do I put something like a YES/NO choice in a bash script ?

Is it something to do with the CASE argument ? Thank you for any help.
Asked by:
TomPating
1355 points
 Report Abuse
 Share Page - Category: Shell Scripting - Tags: User input from BASH script
 Enter your response
Please use Pastie.org to paste lengthy code or to fix formatting issues with code
  • Responses in reverse (4)

Best Answer

echo "Would you like to continue (yes/no)?"

read

case $REPLY in

yes|y) do something;;

no|n) do something else;;



Response by:
stevenrossuk
1325 points
Getkey command is useful

see example below

getkey -c 10 -m "please enter yes to continue.." y

-c 10 means timeout 10 seconds

-m message

y means, user must enter y in 10 seconds

Response by:
jalal
3623 points
Read -p " Do you want to continue(y/n)? " ANS

case $ANS in

y|Y|yes|YES)

#do some commands..

;;

*)

echo user did not enter Y/y/yes/YES

#do some other commands

esac

Response by:
jalal
3623 points
To get the input from the user you'd use the read command, once you have this in a variable you could use case to do different things based on the input.

This example: http://www.thegeekstuff.com/2010/07/bash-case-statement/ seems to be exactly what you're looking for.

Response by:
_SteveWilson ...
4290 points


  • Related Questions
About Us : Contact Us : Etiquette : Terms : CDN Failover : ShorterURL : CDN Fallback : © 2013 Server Circle