Catching SIGINT signal to terminate a custom shell

前端 未结 3 1139
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 02:37

Hope you can help me to resolve this problem.

For school I have to transform Ctrl+C to a command which doesn\'t shut down the shell, but he reminds through

3条回答
  •  悲哀的现实
    2021-01-25 03:02

    As you're talking about doing it from the shell, you probably want:

    $ trap "echo Please type \'exit\' to close the shell." SIGINT
    
    Please type 'exit' to close the shell.
    $
    

    This specifies a command to execute when the listed signal is trapped (the trap command can also trap other signals; SIGINT is the one generated by Ctrl-C). The \' protects the quote from being interpreted by the shell.

提交回复
热议问题