# How to make csh timeout the input?



## sw2wolf (Mar 11, 2013)

```
#!/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!


----------



## jalla (Mar 11, 2013)

ALRM won't trigger onintr, use `kill -INT &&`


----------



## fonz (Mar 11, 2013)

sw2wolf said:
			
		

> ```
> #!/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.


----------



## jalla (Mar 11, 2013)

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


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


----------



## sw2wolf (Mar 12, 2013)

sh is a good choice, thanks!


----------



## SirDice (Mar 13, 2013)

Yes, unless you're slightly masochistic you really don't want to script in csh(1). It's a great shell for interactive use but not for scripting. Best to use sh(1) for scripting. Added bonus, you can run bourne shell scripts on pretty much every unix and unix-like system under the sun 

Old link: CSH Programming Considered Harmful
I always have this one bookmarked: Sh - the Bourne Shell


----------

