在新shell中运行bash命令并执行该命令后,留在新的shell [英] run bash command in new shell and stay in new shell after this command executes
问题描述
我有一个问题。我在寻找这么久的时间回答 - 我该如何在新的bash shell中运行命令,并留在这个新的外壳后,该命令会执行。因此,例如:
的bash -c出口PS1 ='>'和;&安培; LS
将新的外壳,出口PS1,清单目录和...将退出我当前的shell。我想留在新的。
您可以通过实现类似的滥权的的 - rcfile
选项:
庆典--rcfile≤(回声出口PS1 ='>'和;&安培; LS)
手册页:
- rcfile文件
这是文件,而不是系统范围的初始化文件/etc/bash.bashrc和标准的个人初始化文件执行命令〜/ .bashrc中,如果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"
will make new shell, export PS1, list directories and ... will exit to my current shell. I want to stay in the new one.
解决方案You can achieve something similar by abusing the
--rcfile
option:bash --rcfile <(echo "export PS1='> ' && ls")
From bash manpage:
--rcfile file
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屋!