假设我当前位于 zsh shell 中。如果我想在 bash 中运行命令,我当前执行以下两个命令。
exec /bin/bash
# Below is my bash command
help set
Run Code Online (Sandbox Code Playgroud)
如何在一行中实现上述目标而不将 shell 更改为 bash?
使用bash -c。
\n\n\n
-c
\n从第一个非选项参数读取并执行命令command_string,然后退出。[\xe2\x80\xa6]
(来源)
\nbash -c \'help set\'\nRun Code Online (Sandbox Code Playgroud)\n请注意,在您的示例中,如果您没有使用exec而是调用了 alone /bin/bash,则该zsh进程不会被替换bash,它将等待直到bash终止。这意味着您可以在 Bash 中交互地执行您想要执行的操作,然后调用exit(或按Ctrl+ D),您会发现自己处于旧的 Zsh 中。
| 归档时间: |
|
| 查看次数: |
6123 次 |
| 最近记录: |