如何调用bash,在新Shell中运行命令,然后将控制权交还给用户? [英] How to invoke bash, run commands inside the new shell, and then give control back to user?

查看:84
本文介绍了如何调用bash,在新Shell中运行命令,然后将控制权交还给用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这必须是非常简单或非常复杂的,但是我什么都找不到……我试图打开一个新的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆