`source ~/.bash_profile` 在 bash 脚本中不起作用

sen*_*rio 6 bash dot-source

这是一个将 bash 文件移动到主页并使用 source 命令加载它的脚本。

# update.sh
#!/bin/bash
cp -f $PWD/bash_profile ~/.bash_profile
source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

这是行不通的!它用cp -f $PWD/bash_profile ~/.bash_profile.

里面~/.bash_profile有一个新的 PS1 定义。文件已更新,但在打开新窗口之前未发生任何更改。我需要跑source ~/.bash_profile在脚本执行后...

是否可以source在 bash 脚本中运行命令?

jmk*_*may 7

这里的MangeshBiradar :

使用. ./(点空间点斜线)执行 Shell 脚本

使用“dot space dot slash”执行shell脚本时,如下图所示,它会在当前shell中执行脚本,不会分叉子shell。

$ . ./setup.bash

换句话说,这会在当前 shell 中执行 setup.bash 中指定的命令,并为您准备环境。

  • 抱歉,仍然无法从 bash 脚本中执行 source ~/.bash_profile (2认同)