read -l -P "" numberif test -z "$number" set number 2end# do something e.g. echo "Processed"echo "Processed"
I want to read something from the standard input and then do something, e.g. echo "Processed". When Ctrl C
is inputted from the standard input, I wish do something
will never be executed. However, do something
is always be executed.
I tried to use trap to kill %self
, like
trap 'kill %self' INTread -l -P "" numberif test -z "$number" set number 2end# do something e.g. echo "Processed"echo "Processed"
However, %self
should not be killed. This program is triggered by a shortcut. The pid of the program of the same as the pid of the terminal. Thus when kill %self
is executed, the terminal is been closed. This is not expected.
The pid of the program of the same as the pid of the terminal.