How to make csh timeout the input?

Code:
#!/bin/csh

(sleep 3; kill -ALRM $$) & 
onintr bye

echo "please choose WM(1,2,3)"
echo "----------------------"
echo "1:stumpwm-clisp*"
echo "2:stumpwm-ccl"
echo "3:stumpwm-ecl"
echo "----------------------"

set req = 0
set req = $<
switch ($req)
    case [1]:
		xinit
		breaksw
	case [2]:
        xinit ccl
        breaksw
    case [3]:
		xinit ecl
		breaksw
    default:
		breaksw
endsw
exit 0

bye:
	echo "quit without choice"
	exit 1

It does not go to bye.

Sincerely!
 
sw2wolf said:
Code:
#!/bin/csh

(sleep 3; kill -[del]ALRM[/del][red]INT[/red] $$) &

According to csh(1):
...
In shell scripts, the shell's handling of interrupt and terminate signals can be controlled with onintr, and its handling of hangups can be controlled with hup and nohup.
...
Note that most people discourage using csh(1) for scripting, but the choice is of course entirely yours. In sh(1), you can use trap to catch any signal you want, including ALRM.
 
And if you do switch to a sane shell for scripting (read /bin/sh) you could solve the problem at hand more simply with something like

Code:
read -p "prompt? " -t 3 foo
if [ $? != 0 ]; then
  echo "";echo "no input given"; exit 1
fi
echo user said $foo
 
Back
Top