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.

link|improve this question

feedback

3 Answers

up vote 2 down vote accepted

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.
link|improve this answer
Ahha! That's what I was looking for. – Brian Dec 8 '11 at 15:41
feedback

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"
link|improve this answer
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
feedback

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.

link|improve this answer
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
feedback

Your Answer

 
or
required, but never shown

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