Linux shell script trap only works sometimes

7 views
Skip to first unread message

Kristian

unread,
Jun 24, 2016, 11:08:57 AM6/24/16
to jenkins...@googlegroups.com
Hey,

I have a question.

I created a job with this sample script:
**************
#!/bin/bash

trap "echo 'User has aborted this script'" TERM

result=0

for i in {0..1000..20}
do
result=$(($result + 1))
    echo $result ...
    sleep 1
done

echo "Result is $result"
**************

When I start this script and abort the job, I only sometimes get the message 'User has aborted this script'. Why only sometimes?
Reply all
Reply to author
Forward
0 new messages