如何调用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-不退还给
- https://unix.stackexchange.com/questions/123103/如何在执行命令后保持重击运行
- 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屋!