Quantcast
Channel: Active questions tagged fish - Stack Overflow
Viewing all articles
Browse latest Browse all 92

How to end the `read` command by ctrl c?

$
0
0
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.


Viewing all articles
Browse latest Browse all 92

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>