在新 shell 中运行 bash 命令并在此命令执行后留在新 shell [英] run bash command in new shell and stay in new shell after this command executes
问题描述
我有一个问题.我正在寻找这个答案很长时间 - 我如何在新的 bash shell 中运行命令并在这个命令执行后留在这个新的 shell 中.比如:
I've got a problem. I'm searching for long time for this answer - how can I run command in new bash shell and stay in this NEW shell after this commands executes. So for example:
bash -c "export PS1='> ' && ls"
将创建新的 shell,导出 PS1,列出目录,... 将退出到我当前的 shell.我想留在新的.
will make new shell, export PS1, list directories and ... will exit to my current shell. I want to stay in the new one.
推荐答案
您可以通过滥用 --rcfile
选项来实现类似的效果:
You can achieve something similar by abusing the --rcfile
option:
bash --rcfile <(echo "export PS1='> ' && ls")
来自 bash 手册页:
--rcfile 文件
--rcfile file
如果 shell 是交互式的,则从文件而不是系统范围的初始化文件/etc/bash.bashrc 和标准的个人初始化文件 ~/.bashrc 执行命令
Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive
这篇关于在新 shell 中运行 bash 命令并在此命令执行后留在新 shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!