ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My input is always treated like invalid input with this script and I'm trying to work out why. I've cobbled this together from a ton of scripts I found online and I've had all kinds of mixed results, but this is the closest I've gotten to something that works...and yet...
Code:
#!/bin/bash
echo "INSTALLER"
echo "THIS IS PROVIDED WITHOUT WARRANTY"
echo "ARE YOU SURE YOU WANT TO PROCEED?"
echo "I AGREE TO CONTINUE-QUIT TO EXIT"
options=("I AGREE" "QUIT")
select opt in "${options[@]}"
do
case $opt in
"I AGREE")
echo "CONTINUTING"
break
;;
"QUIT")
echo "QUITTING"
break
exit;;
*) echo invalid option
continue
;;
esac
done
Any advice on what I'm getting out of place here would be greatly appreciated.
Last edited by VolumetricSteve; 10-09-2016 at 09:56 AM.
Firstly, please use [code][/code] tags around code to keep formatting.
You have supplied code but not what you are entering to receive the invalid input?
Having run the code on my machine, entering 1 or 2 seems to work just fine and anything else is received as invalid input correctly??
I meant to imply that any input I give it gets handled as invalid input. (or it had in previous versions, anyway)
Wow, so...I just completely misunderstood the purpose of select. I thought the way it worked was to get the user to type "I AGREE' instead of a numerical response, I see numerical responses are working now (where they hadn't been across the many previous versions of this script)
If I want to make my case statement hinge on the literal string input "I AGREE" can I still use select or do I need to use something else? Thanks for your help.
Goumba, awesome. I've read (ha) with read that you need to worry about data sanitation, but I guess that's the price for grabbing a string literal from stdin.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.