Ask user to confirm

Confirm() { read -sn 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]]; }
Returns true if user presses the key. Use it like Confirm "Continue" && do action

12
By: frans
2010-11-22 11:01:14

1 Alternatives + Submit Alt

What Others Think

It's usually good UI to display the response so the user can confirm that he really did press the wrong key so I would recommend leaving of the -s. If you'd like to have an echo after the prompt so the next output is not on the same line as the prompt, you can do one of these: confirm() { read -n 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]] && echo || { echo; return 1;} } confirm() { read -n 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]]; local r=$?; echo; return $r; }
dennisw · 627 weeks ago
The fact is that in scripts where i used that, i used the verbosity of the involved action like: Confirm "Delete files" && rm -v $Files || echo "cancelled"
frans · 627 weeks ago
how do i halt the script if user pressed N at Confirm() { read -sn 1 -p "$1 [Y/N]? "; [[ $REPLY = [Yy] ]]; } Confirm "Continue?"
rubo77 · 573 weeks and 6 days ago
if you mean 'exit', then it's simply: Confirm "Continue" || exit The "?" is already in the function so there's no need to pass it in the parameter.
frans · 573 weeks and 6 days ago
https://seofox.ir/seo/ https://seofox.ir/gray-hat-seo/ https://seofox.ir/search-engine/ https://seofox.ir/page-rank/ https://seofox.ir/backlink-definition/ https://seofox.ir/seo-techniques/ https://seofox.ir/technical-seo/ https://seofox.ir/on-page-seo/ https://seofox.ir/seo-tools/ https://seofox.ir/off-page-seo/ https://seofox.ir/seo-consultation/ https://seofox.ir/on-page-seo/ https://seofox.ir/google-seo-book/ https://seofox.ir/add-site-in-google/ https://seofox.ir/category/seo/ https://seofox.ir/seo-training/ https://seofox.ir/order/ https://seofox.ir/page-speed/ https://seofox.ir/seo-company https://seofox.ir/white-hat-seo/ https://seofox.ir/seo-principles/ https://seofox.ir/category/seo-content/ https://seofox.ir/seo-checklist/ https://seofox.ir/category/seo-content/ https://seofox.ir/google-algorithms/ https://seofox.ir/google-penalty-removal/ https://seofox.ir/rules-of-link-building/ https://seofox.ir/analyze-seo/ https://seofox.ir/backlink/ https://seofox.ir/seo-services-prices/ ??? ? ????? ????
seofox · 43 weeks and 1 day ago
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. manga
muneerahmed · 30 weeks ago
Excellent article plus its information and I positively bookmark to this site because here I always get an amazing knowledge as I expect. Thanks for this to share with us haremmanga
muneerahmed · 28 weeks and 1 day ago
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. Anna
muneerahmed · 25 weeks and 6 days ago
Good composed article. It will be steady to any individual who uses it, including me. Continue doing what you are doing – can'r hold up to peruse more posts. Samsung Galaxy a 10 manual instructions
muneerahmed · 25 weeks and 6 days ago
I am energetic to find your perceived technique for forming the post. By and by you make it straightforward for me to fathom and execute the thought. Thankful to you for the post. Traffic jam paragraph
muneerahmed · 25 weeks and 5 days ago
I simply wanted to thank you a lot more for your amazing website you have developed here. It can be full of useful tips for those who are actually interested in this specific subject, primarily this very post. Corel Painter 2023
muneerahmed · 24 weeks and 1 day ago
The first phase the preparation should, theoretically, be uninfluenced by the intended intensity and duration of the sound which is subsequently produced. In fact, however, so quickly are the three phases accomplished that the pianist rarely has capacity to think, in performance, of each phase separately. Iolo System Mechanic Standard
muneerahmed · 24 weeks ago
So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site. laser hair removal training
muneerahmed · 24 weeks ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
rahimhh21 · 13 weeks and 3 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me USA USA USA USA USA USA Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 4 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: