PDA

View Full Version : [all variants] Shell script help (handling timeouts)



kpkeerthi
April 15th, 2009, 12:56 PM
Here is a pseudo code of what I need:


timeout_seconds='30'

Prompt user for input

If user did not respond within $timeout_seconds
execute command-x
else
execute command-y
end-if

exit


Can someone please provide the bash equivalent?

KyleBrandt
April 15th, 2009, 01:43 PM
'read -h'

Spoon feeding:


#!/bin/bash
timeoutSeconds=10
read -t $timeoutSeconds foo
if [[ -n $foo ]]; then
echo $foo
else
echo 'baz'
fi

kpkeerthi
April 15th, 2009, 01:51 PM
Thanks for feeding ;)