I'm still fairly new to Linux, but I'm even newer to the notions of SSH and PUTTY. After I SSH into a linux box, I fire off the following command:
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. I did research and came to the following conclusions:
In csh, onintr -
can be used to block signals in a given script. This got me thinking about putting onintr -
into the cshrc file: That way it would be executed each time I run the above command. But that line is only local to one script, so it wouldn't have any real global effect like I wanted.
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. command. So I tried launching bash instead and modifying the code to fit. 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.
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.
I'm at odds about how to go about resolving this issue. How can I have the shell ignore Ctrl+C by default? Should I put onintr -
into cshrc? Or would I be better off using bash and running the trap command? 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 /; set echo off; set term=dumb; set echo on; pwd; bash -i;'
You could just place trap
before the bash -i
, as to keep bash -i
from receiving the signal, like in the following:
bash -c ' cd /; set echo off; set term=dumb; set echo on; pwd; trap "" 2; bash -i;'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.