How to export a variable in bash

后端 未结 4 1402
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 02:56

I need to set a system environment variable from a bash script that would be available outside of the current scope. So you would normally export environment variables like

4条回答
  •  执笔经年
    2020-12-11 03:08

    Not really - once you're running in a subprocess you can't affect your parent.

    There two possibilities:

    1) Source the script rather than run it (see source .):

        source {script}
    

    2) Have the script output the export commands, and eval that:

        eval `bash {script}`
    OR:
        eval "$(bash script.sh)"
    

    EDIT: Corrected the second option to be eval rather than source. Opps.

提交回复
热议问题