[Gllug] Yes or no?

Ben Fitzgerald ben_m_f at yahoo.co.uk
Mon Nov 28 11:24:54 UTC 2005


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? If you have problems with this wasting cpu
cycles then you must be asking a +lot+ of questions ;-)

ben.

-- 
Registered Linux user number 339435
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list