Handle a signal: Difference between revisions

Added bash solution
(Added bash solution)
Line 880:
c=`expr $c + 1`
done</lang>
 
{{works with|bash}}
Note that the following solution only works on systems that support a version of sleep that can handle non-integers
<lang bash>
#!/bin/bash
trap 'echo "Run for $((s/2)) seconds"; exit' 2
s=1
 
while true
do
echo $s
sleep .5
let s++
done
</lang>
 
Sample output:
<pre>
1
2
3
4
5
^CRun for 2 seconds
</pre>
 
{{works with|zsh}}