How to set an environment variable only for the duration of the script?

前端 未结 3 905
孤街浪徒
孤街浪徒 2020-12-04 08:47

On Linux (Ubuntu 11.04) in bash, is it possible to temporarily set an environment variable that will only be different from the normal variable for the duration of the scrip

相关标签:
3条回答
  • 2020-12-04 09:15

    Just put

    export HOME=/blah/whatever
    

    at the point in the script where you want the change to happen. Since each process has its own set of environment variables, this definition will automatically cease to have any significance when the script terminates (and with it the instance of bash that has a changed environment).

    0 讨论(0)
  • 2020-12-04 09:23
    env VAR=value myScript args ...
    
    0 讨论(0)
  • 2020-12-04 09:36
    VAR1=value1 VAR2=value2 myScript args ...
    
    0 讨论(0)
提交回复
热议问题