launch xterm/urxvt with command and return to shell after exit

67 views Asked by At

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?

1

There are 1 answers

2
John Bayko On BEST ANSWER

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")