首页 文章

在shell脚本中导出路径的意义是什么?

提问于
浏览
0

我在shell脚本中看到过以下两行 . 我是unix脚本的新手,设置这个有什么用?

PATH = $ PATH:/ bin:/ usr / bin:/ usr / sbin:/ sbin:/ etc:/ usr / ucb:/ usr / ccs / bin:/ usr / local / bin export PATH

提前致谢

2 回答

  • 0

    如果你 export (无论如何,我认为是你的shell),它将标记在随后执行的命令中可用的东西 .

    $ FOO=1 # Set the variable
    $ echo $FOO # Check the value
    1
    $ bash # New shell here. 
    
    $ echo $FOO # No value since it's not exported
    
    $ exit # Quit the subshell
    $ export FOO # Export it
    $ bash
    $ echo $FOO # It has a value now
    1
    

    export 是一个内置于bash的shell,所以做一个 help export 会给你更多的信息 .

  • 0

    显式导出PATH并没有什么坏处,但通常没有效果,因为在启动shell脚本时,PATH变量几乎肯定已标记为已导出 .

相关问题