使用Shell脚本添加到$ PATH [重复]

问题描述 投票:0回答:2

这个问题在这里已有答案:

我想在文件PATH上添加Linux Ubuntu 18.04上的path.sh,我的文件包括:

 #!/bin/bash
 export PATH="$PATH:/root/.local/bin"

chmod+x path.sh,但当我运行它./path.sh路径不添加当我键入echo $PATH

但当我输入终端export PATH="$PATH:/root/.local/bin"时,它加入了我的PATH

我错过了我的档案吗?

bash shell scripting ubuntu-16.04 ubuntu-18.04
2个回答
1
投票

我们来咨询man bash

export [-fn] [name[=word]] ...
export -p
       The  supplied names are marked for automatic export to the envi-
       ronment of subsequently executed commands.

注意“随后执行的命令”,因此一旦脚本结束,脚本的效果就会结束。


0
投票
source path.sh

添加此步骤很好。

© www.soinside.com 2019 - 2024. All rights reserved.