0

I want to launch a continuous running command with xterm or urxvt and after pressing Ctrl+C to exit the command I want to get a shell to enter further commands in the same window.

With non-continuous running commands I can do

urxvt -hold -e sh -c "echo foo; sh"

But with continuous running commands this does not work

urxvt -hold -e sh -c "tail -f /dev/null; sh"

After pressing Ctrl+C the command is killed but urxvt enters an unresponsive state and does not open a shell. Same thing happens with xterm.

Any solutions for this?

flappix
  • 2,038
  • 17
  • 28

1 Answers1

1

Ctrl+C generates a SIGINT signal, bash stops the entire sequence by default. It actually lets the signal pass to the current command, and analyses the exit status of rhe command - if the command handled the SIGINT, bash continues the script, otherwise the SIGINT shows up in the exit status and bash terminates the command sequence.

There's an explanation here: https://unix.stackexchange.com/questions/479023/why-does-this-script-keep-running-after-receiving-sigint

In that case, the questioner used sudo to wrap the command with a signal handler. You could also look at using a subshell with the trap command.

(Asker reports that this works: urxvt -e sh -c "trap sh SIGINT; tail -f /dev/null")

John Bayko
  • 746
  • 4
  • 7
  • Thanks a lot for your answer, this works great. You could you just add the snippet ```urxvt -e sh -c "trap sh SIGINT; tail -f /dev/null"``` to your answer? Then I'll mark it as the accepted answer. – flappix Jul 31 '23 at 17:21
  • Readers can see that in your comment here, but okay I'll add that and credit you. – John Bayko Jul 31 '23 at 20:57