
On Mon, 2006-01-02 at 17:53 +1100, Leslie Katz wrote:
#!/bin/bash # Shows how to read a line from stdin
echo "Would you like to exit this script now?" read answer if [ "$answer" = y ] then echo "Exiting..." exit 0 fi
Bash often has problems with the keyboard buffer not being completely emptied, so you end up with the read being completed immediately with the results of the buffer. Add the following just before the read to empty the buffer. while :; do read -t 0; if [ "$?" -eq "1" ]; then break; fi; done It basically just loops reading for 0 seconds until read says there is nothing left in the buffer to read. There are probably more concise ways of doing it, but this is the clearest way I've found. Cheers -- Matt Brown matt(a)mattb.net.nz Mob +64 275 611 544 www.mattb.net.nz