Can I export a variable to the environment from a bash script without sourcing it?

前端 未结 7 1665
半阙折子戏
半阙折子戏 2020-11-22 05:51

Suppose that I have this script

export.bash:

#! /usr/bin/env bash
export VAR=\"HELLO, VARIABLE\"

When I execute th

相关标签:
7条回答
  • 2020-11-22 06:57

    Another workaround that, depends on the case, it could be useful: creating another bash that inherites the exported variable. It is a particular case of @Keith Thompson answer, will all of those drawbacks.

    export.bash:

    # !/bin/bash
    export VAR="HELLO, VARIABLE"
    bash
    

    Now:

    ./export.bash
    echo $VAR
    
    0 讨论(0)
提交回复
热议问题