4

Is it possible to suspend a bash that was invoked by another bash? For example, if I use su to become a different user but want to switch back to my own user for a moment. For another example, in an SSH session, I can use the ~ shortcut (~, ^Z) to suspend the remote shell and return to my local shell (but that's obviously an SSH feature, not the shell).

bash intercepts ^Z to do its own process control, so it must be a separate command (if it's even supported). But trying to find it only results in information about the normal process control.

5

Bash has a suspend builtin:

suspend: suspend [-f]
    Suspend shell execution.

    Suspend the execution of this shell until it receives a SIGCONT signal.
    Unless forced, login shells cannot be suspended.

    Options:
      -f    force the suspend, even if the shell is a login shell

    Exit Status:
    Returns success unless job control is not enabled or an error occurs.
  • Ahha! That's what I was looking for. – Brian Dec 8 '11 at 15:41
5

Try with:

kill -STOP $$

where $$ is the PID of the current shell.

You can bind it to Alt + z for example by adding to ~/.inputrc:

"\ez": "kill -STOP $$\n"
  • Excellent, thank you! Never knew about .inputrc – Brian Dec 6 '11 at 17:51
  • It controls the way bash reads/edit the user input, see man readline, it can be very useful, it's worth to mention the commands: history-search-backward and history-search-backward. – cYrus Dec 6 '11 at 18:08
1

Not exactly what you were asking for, but I normally use screen when I'm doing things like that. However, screen is not installed by default on all systems.

  • I actually work in screen all the time. I run screen on my local machine and have SSH sessions into a bunch of others. So I don't typically run screen on the remote systems because screen-within-screen is clumsy. And I'm too lazy to open another session :-). I'm used to hitting ^Z in vim to suspend it when I need to run some commands (I know vim has ! but it's not the same as a shell). – Brian Dec 8 '11 at 15:45

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.