【问题标题】:Add to $PATH with Shell Script [duplicate]使用 Shell 脚本添加到 $PATH [重复]
【发布时间】:2019-05-12 04:28:21
【问题描述】:

我想从文件path.sh 中添加PATHLinux Ubuntu 18.04,我的文件包括:

 #!/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


    【解决方案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.
    

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

    【讨论】:

      【解决方案2】:
      source path.sh
      

      添加这一步就可以了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-18
        • 1970-01-01
        • 2016-09-21
        • 2016-12-05
        • 2018-03-02
        • 2015-09-01
        • 2019-12-06
        • 1970-01-01
        相关资源
        最近更新 更多