[SOLVED] conditional statements: Forgot how to read both capital/ lower case
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.
conditional statements: Forgot how to read both capital/ lower case
Before I am sure that I saw some tutorial that taught that you can write a program with a if/else conditional statements that can accept the following answers:
#!/bin/bash
unset ans
echo -en "Enter into call mode? > "
read ans
#Conditional statement
if [ "$ans" == "[Yy][Ee][Ss] ]; then
echo "You answered "$ans", Welcome!"
elif [ "$ans" == "[Nn][Oo]" ]; then
echo "You answered "$ans", Denied"
else
echo "Input not valid."
fi
There must be something wrong with my web searching skills or something not to be able to find this again. The answer stems off of [0-9a-zA-Z] being shorthand for numbers 0-9, lower case letters a-z and upper case letters A-Z. I even searched in the ebooks: Bash Beginners Guide and Advanced Bash Scripting.
Last edited by andrew.comly; 06-21-2016 at 06:33 AM.
Reason: correction
Generally speaking, languages are case-sensitive in string comparison. (But, as always, there are exceptions.) Regular expressions (with the "/i" modifier) can reliably be used to do case-insensitive compares. Or, you can use a "to-upper/lower case" function and compare against a literal of that case.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.