Skip to main content
26 events
when toggle format what by license comment
Sep 26, 2022 at 18:00 comment added Jacktose @wkw Broken link. Nice general purpose yes/no function: current version; archived copy of orig.
Jan 18, 2022 at 22:01 comment added ajay4q @henning [Yy][eE][sS] is a whole thing. So that case will pass the 'yes' in any case-sensitivity form of inputs like YES YEs YeS Yes yES yEs yeS yes. or simply if you can use Y or y also as | [yY] is combined in that.
Jan 12, 2022 at 14:06 comment added henning no longer feeds AI What is the purpose of [eE][sS]?
Nov 17, 2019 at 9:43 history edited Noam Manos CC BY-SA 4.0
Removed the `+` at the end of `[yY][eE][sS]|[yY])`, otherwise, "YesYYESyesYy" would be confirmed.
Sep 6, 2019 at 21:54 comment added Brian Duncan @DennisWilliamson I see! Thanks for the clarification. I think what I was trying to say is that since we are only checking one boolean value, we shouldn't need a case statement. But it sounds like (and from what I've read) the case construct here provides the pattern-matching we couldn't get elsewhere in a widely compatible way. That's just shell-scripting I suppose :\
Sep 6, 2019 at 19:12 comment added Dennis Williamson @BrianDuncan: The reason to use case is for versions of Bash or other shells which don't have regex matching. My answer already includes the regex version and says that the confirm function "would work similarly with the other two" matching options I show.
Sep 6, 2019 at 18:48 comment added Brian Duncan For confirm, don't think you need the case statement stuff, just the test, and that will be the result of your function. (Line 1) read -r ... (Line 2) [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
Sep 19, 2017 at 13:29 history rollback Dennis Williamson
Rollback to Revision 6
Sep 19, 2017 at 5:12 history edited BMW CC BY-SA 3.0
added 2 characters in body
Aug 4, 2017 at 14:50 comment added Mikael Roos Use case "${response:-$2}" in to enable sending default answer to the function as confirm "Oh really [Yn]?" "Y" && do-nasty-thing. And perhaps use $REPLY instead of $response.
May 23, 2017 at 12:34 history edited URL Rewriter Bot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
S Jan 21, 2017 at 0:14 history edited Jonathan Leffler CC BY-SA 3.0
Make the code a bit more consistent, etc.
S Jan 21, 2017 at 0:14 history suggested slayer CC BY-SA 3.0
If $response is an empty string, it will give an error. To fix, simply add quotation marks: "$response".
Jan 20, 2017 at 21:50 review Suggested edits
S Jan 21, 2017 at 0:14
Jul 29, 2015 at 15:41 comment added Dennis Williamson @Ray: Bash runs on a lot of non-Linux machines and there are a lot of older Linux versions in production. You might be surprised at how many systems are using Bash 3, and even 2.
Jul 29, 2015 at 15:25 comment added Ray Foss Fedora 21, CentOS 6 and Debian Wheezy run 4.2+ I deal with a lot of linux machines, I don't know of a single relevant linux distro not using 4.x
Apr 30, 2015 at 17:55 comment added wkw Nice general purpose yes/no function. supports a prompt strong, and optionally making 'y' or 'n' default.
Jan 24, 2015 at 18:44 comment added João Cunha @DennisWilliamson correct, that's what I tried to mean. Can't edit my comment for some reason.
Jan 24, 2015 at 18:20 comment added Dennis Williamson @JoãoCunha: That would be "not match" rather than "not equal" since =~ is the regex match operator.
Jan 24, 2015 at 16:21 comment added João Cunha Worth mentioning that if you want to check not equal to on the second example, you should cast the $response variable. Eg: if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]].
Oct 31, 2013 at 11:42 history edited James CC BY-SA 3.0
Y/n -> y/N as mentioned in comment
Jun 24, 2013 at 15:34 review Suggested edits
Jun 24, 2013 at 15:36
Aug 1, 2012 at 11:58 comment added Simon A. Eugster Actually it should be [y/N] and not [Y/n] for the current test.
Jul 16, 2010 at 9:20 history edited Dennis Williamson CC BY-SA 2.5
added another version
Jul 16, 2010 at 2:45 vote accept nonopolarity
Jul 12, 2010 at 20:36 history answered Dennis Williamson CC BY-SA 2.5