如何在 bash 中暂停 bash

Bri*_*ian 4 keyboard-shortcuts bash shell process

是否可以暂停由另一个 bash 调用的 bash?例如,如果我曾经su成为一个不同的用户,但想暂时切换回我自己的用户。再举一个例子,在 SSH 会话中,我可以使用 ~ 快捷方式 (~, ^Z) 挂起远程 shell 并返回到我的本地 shell(但这显然是 SSH 功能,而不是 shell)。

bash 拦截 ^Z 以进行自己的过程控制,因此它必须是一个单独的命令(如果它甚至受支持)。但是试图找到它只会导致有关正常过程控制的信息。

cYr*_*rus 5

尝试:

kill -STOP $$
Run Code Online (Sandbox Code Playgroud)

其中$$PID当前外壳。

您可以将它绑定到Alt+z例如通过添加到~/.inputrc

"\ez": "kill -STOP $$\n"
Run Code Online (Sandbox Code Playgroud)


Mar*_*ian 5

Bash 有一个suspend内置:

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.
Run Code Online (Sandbox Code Playgroud)