I need to write a script that has the following behaviour:
- If the script receives the signal
SIGINT
, then the script increments the value of the counter by one and prints its value to the standard output. - If it receives the signal
SIGQUIT
, then it decreases the value of the counter by one and prints its value to standard output. - If the current value of the counter is less than
-5
or more than+5
, then the program terminates.
#!/bin/bash
count=0
while [ $count -lt -5 ] && [ $count -gt 5 ]; do
sleep 1
trap 'count=$(expr $count + 1)' SIGINT
echo $count
trap count=$(expr $count - 1) SIGQUIT
echo $count
done
I wrote this code, but I am not sure what I am doing wrong.