如何调用 bash,在新 shell 中运行命令,然后将控制权交还给用户? [英] How to invoke bash, run commands inside the new shell, and then give control back to user?
问题描述
这必须非常简单或非常复杂,但我找不到任何关于它的信息...我正在尝试打开一个新的 bash 实例,然后在其中运行一些命令,并将控制权交还给用户在同一个实例中.
This must either be really simple or really complex, but I couldn't find anything about it... I am trying to open a new bash instance, then run a few commands inside it, and give the control back to the user inside that same instance.
我试过了:
$ bash -lic "some_command"
但这会在新实例中执行 some_command
,然后关闭它.我希望它保持打开状态.
but this executes some_command
inside the new instance, then closes it. I want it to stay open.
还有一个可能影响答案的细节:如果我可以让它工作,我将在我的 .bashrc
中使用它作为别名,所以 alias
的奖励积分代码> 实现!
One more detail which might affect answers: if I can get this to work I will use it in my .bashrc
as alias(es), so bonus points for an alias
implementation!
推荐答案
bash --rcfile <(echo '. ~/.bashrc; some_command')
免除临时文件的创建.其他网站上的问题:
dispenses the creation of temporary files. Question on other sites:
- https://serverfault.com/questions/368054/run-an-interactive-bash-subshell-with-initial-commands-without-returning-to-the
- https://unix.stackexchange.com/questions/123103/how-to-keep-bash-running-after-command-execution
这篇关于如何调用 bash,在新 shell 中运行命令,然后将控制权交还给用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!