[Gllug] Yes or no?

John Winters john at sinodun.org.uk
Mon Nov 28 12:23:39 UTC 2005


On Mon, 2005-11-28 at 11:24 +0000, Ben Fitzgerald wrote:
> On Mon, Nov 28, 2005 at 09:35:20AM +0000, Jon Dye wrote:
> > I'm trying to write a small (bash) shell script that will run a program
> > on each file in a directory, show you the output and then ask you to
> > confirm or reject the output (and therefore keep or delete the original
> > file).
> > 
> > It strikes me there should be an easy way to display a question and
> > prompt for a yes or no (or y and n) answer.  Is there a simple program
> > that will do this and return with a zero or non-zero result that I could
> > use in my script?
> > 
> > I'm sure I can work it our using read or something but it seems a bit
> > clunky.
> 
> I'd be surprised if someone has written a more efficient program than
> the following:
> 
> read answer
> [ "$answer" == "yes" ] && do_something_function
> [ "$answer" != "yes" ] && do_something_else_function
> 
> What's wrong with that?

Since you ask, I would expect at the very least for the case-sensitivity
to be removed and for the code to accept just "y" as well.  The above
would do only for a question like:

"This will erase your entire hard disk.  Are you sure you want to
proceed?  Type "yes" to continue, anything else to abort:"

John

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list