Yes you can use the trap command. The general syntax of the command is :
Code:
trap command signal
The command
command is executed when the signal
signal is caught
Since scripts are normally interpreted from top to bottom, so you must specify the trap command before the part of the script you wish to protect.
The signal INT (value = 2) is generally passed when you press CTRL-C. Type man signal to know more about signals.
You're saying that when you press CTRL-C the application knows what to do, i.e. it gets the signal and quits whereas the script doesn't quit and launches the application again and again with another set of parameter until the while loop is over. Right?
You want that the script should terminate whenever a CTRl-C signal is passed.
This is wierd at least to me. I tried calling another script form one script and then pressing CTRL-C, both scripts terminated for me. I don't know why only the application is terminating in your case and not the script also.
You could try something like this :
Code:
#!/bin/sh
nr_threads=20
start_table=0
step=16
export out=0
trap 'exit 0' INT or simply trap INT
while [ $start_table -lt 256 ]
do
launch="./index -t:$nr_threads -b:$start_table -s:$step"
echo "$launch"
$launch
let "start_table = $start_table + $step"
done
If you solved the problem do let us know. Many other people might be having similar problems.
Hope this helps!