0

Is it possisble in bash script to use parameters in a function, which is called after interrupt signal? Here's my code:

    inCaseOfInterrupt ()
    {
        while [ $# -gt 0 ]
        do
                echo "$1"
                shift
        done
        exit 0
    }

And in the other part of my script I have:

trap inCaseOfInterrupt 2

But it doesn't recognize my parameters. How can I use parameters in a function after script gets interrupt signal?

0

1 Answer 1

0
trap 'inCaseOfInterrupt 2' 2

Or, with a signal name:

trap 'inCaseOfInterrupt 2' INT
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, but when I pass parameters: "test1 test2 test3", I get "2" on the output instead of "test1 test2 test3", which I expected.
Pass parameters how?
When I run my script in Bash shell: ./myScript test1 test2 test3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.