Reputation: 387
Is it possible to time out a user input for the c shell? My code so far is :
#!/bin/csh -f
set COUNT = 5
printf "INFO: Start ok (0/1)? "
set INPUT = 0
while ($COUNT > 0 && $INPUT == 0)
printf "\b%d" "$COUNT"
set INPUT = <$
sleep 1
@ COUNT --
end
if ($INPUT == 1) then
./execute.sh
end
If no input is given, I want to execute a shell script; if not i want to skip this part. Unfortunately, the skript does not skip the input part but waits for the input. Any solutions for this problem? Thanks a lot guys!!!
Upvotes: 1
Views: 1072
Reputation: 440
try this for non-blocking user input in tcsh shell:
set TMPFILE = `mktemp`
set COUNT = 5
printf "INFO: Start ok (0/1)? "
stty -F /dev/tty -icanon
while ($COUNT > 0 && -z $TMPFILE)
printf "\b%d" "$COUNT"
sleep 1
(dd bs=1 count=1 iflag=nonblock > $TMPFILE) >& /dev/null
set INPUT = `cat $TMPFILE`
@ COUNT--
end
stty -F /dev/tty icanon
echo ""
if ("$INPUT" == "1") then
./execute.sh
endif
Upvotes: 1