Re: Can't stop script with ctrl-c
2006-08-19, 18:16(+00), Dave Farrance:
> This script uses the "festival" speech synthesis app to keep saying the
> word hello. Why can't I stop it with ctrl-c? Is there a workaround?
>
> #!/bin/bash
> while true; do
> echo "hello" | festival --tts
> done
Yes, bash has a funny way of handling sigint. bash will only
exit upon receiving a SIGINT if the current command was killed
by that sigint as well (apparently).
So, if "festival" ignores the sigints, it will not exit.
You can try:
#! /bin/bash -
while :; do
echo "hello" | festival --tts &
wait
done
Then, the CTRL-C will interrup the "wait" instead of festival
(which will continue running).
Or:
#! /bin/bash -
trap 'exit 1' INT
while :; do
echo "hello" | festival --tts
done
This way, bash will still block the SIGINT but will execute its
handler (exit 1) when festival finishes.
--
Stéphane
|