Results 1 to 2 of 2
Hi,
I've wrote a script that I want to trap SIGINT (ctrl-C) and print out some values in variables before exit. I've put that print/echo code into a function but ...
- 11-18-2011 #1Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
Bash signal trapping problem
Hi,
I've wrote a script that I want to trap SIGINT (ctrl-C) and print out some values in variables before exit. I've put that print/echo code into a function but when I press ctrl-C the script only seems to execute the first echo statement in that function prior to exit.
I'm wondering if there is some limitation on signal trapping that precludes doing more than a single task/command within a trap's function.
A pseudo-code of what I'm trying to do would be:
<code>
#!/bin/bash
function a_bend() {
echo $this
echo $that
echo $those
exit 1
}
trap a_bend SIGINT
this=$1
that=`expr $this % 7`
those=`expr $that * 100`
while [ $those -gt 0 ]
do
sleep 10
those=`expr $those - 1`
done
</code>
I can't imagine this not working, but I'm stumped.
Thanks
- 11-20-2011 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
The '*' in your expression needs to be escaped when using "expr". Maybe you should look at the bash "((expression))" where you could do:
Code:this=${1:-1000} ((that=this % 7)) ((those=that * 100))


Reply With Quote