gpt4 book ai didi

bash - 在新 shell 中运行 bash 命令并在执行此命令后留在新 shell 中

转载 作者:行者123 更新时间:2023-11-29 08:42:26 24 4
gpt4 key购买 nike

我有一个问题。我正在寻找这个答案很长时间 - 如何在新的 bash shell 中运行命令并在执行此命令后留在这个新的 shell 中。例如:

bash -c "export PS1='> ' && ls"

将创建新的 shell、导出 PS1、列出目录并...将退出到我当前的 shell。我想住在新的。

最佳答案

您可以通过滥用 --rcfile 选项来实现类似的目的:

bash --rcfile <(echo "export PS1='> ' && ls")

来自 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

关于bash - 在新 shell 中运行 bash 命令并在执行此命令后留在新 shell 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7192575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com