简体   繁体   English

启动时忽略csh中的信号

[英]Ignore signals in csh on startup

I'm still fairly new to Linux, but I'm even newer to the notions of SSH and PUTTY. 我对Linux还是很陌生,但对SSH和PUTTY的概念甚至更新。 After I SSH into a linux box, I fire off the following command: SSH进入Linux机器后,我启动以下命令:

csh -c 'cd /; set echo off; set term=dumb; set echo on; pwd; csh -i'

This is all well and good except for the headaches caused by signal interrupts, such as Ctrl+C. 除了由信号中断(例如Ctrl + C)引起的头痛之外,这一切都很好。 I did research and came to the following conclusions: 我做了研究,得出以下结论:

  1. In csh, onintr - can be used to block signals in a given script. 在csh中, onintr -可用于阻止给定脚本中的信号。 This got me thinking about putting onintr - into the cshrc file: That way it would be executed each time I run the above command. 这让我开始考虑将onintr -放入onintr -文件中:这样,每次我运行上述命令时,它将被执行。 But that line is only local to one script, so it wouldn't have any real global effect like I wanted. 但是该行仅对一个脚本而言是本地的,因此它不会像我想要的那样具有任何实际的全局效果。

  2. I found that bash, unlike csh, has the trap command - a non-script-specific command that will redefine how certain signals are handled during the entire shell session. 我发现bash与csh不同,它具有trap命令-一种非特定于脚本的命令,它将重新定义在整个Shell会话期间如何处理某些信号。 command. 命令。 So I tried launching bash instead and modifying the code to fit. 因此,我尝试启动bash并修改代码以使其适合。 Looking at the bash man pages, I interpreted that bash -c behaves in much of the same way as csh -c so to replicate the above command, I tried to replace csh with bash and append trap "" 2 to the command. 在查看bash手册页时,我认为bash -c行为与csh -c大致相同,因此要复制上述命令,我尝试用bash替换csh并将trap "" 2附加到命令中。

Therefore, the full command would be: 因此,完整的命令将是:

bash -c' cd /; set echo off; set term=dumb; set echo on; pwd; bash -i; trap "" 2'

But bash -c does not necessarily behave like csh -c , at least in this instance. 但是,至少在这种情况下, bash -c行为不一定像csh -c一样。


I'm at odds about how to go about resolving this issue. 关于如何解决此问题,我有些分歧。 How can I have the shell ignore Ctrl+C by default? 默认情况下,如何让Shell忽略Ctrl + C? Should I put onintr - into cshrc? 我应该将onintr -放入onintr -吗? Or would I be better off using bash and running the trap command? 还是我最好使用bash并运行trap命令? How should I go about implementing the better solution? 我应该如何实施更好的解决方案?

Although I don't fully see why you would use a statement such as 尽管我还没有完全理解为什么您会使用诸如

bash -c ' cd /; bash -c'cd /; set echo off; 关闭回声; set term=dumb; 设定期限=哑; set echo on; 设置回声 pwd; pwd; bash -i;' bash -i;'

You could just place trap before the bash -i , as to keep bash -i from receiving the signal, like in the following: 您可以将trap放在bash -i之前,以防止bash -i接收信号,如下所示:

bash -c ' cd /; bash -c'cd /; set echo off; 关闭回声; set term=dumb; 设定期限=哑; set echo on; 设置回声; pwd; pwd; trap "" 2; 陷阱“” 2; bash -i;' bash -i;'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM