Defining a variable with or without export

后端 未结 14 1753
借酒劲吻你
借酒劲吻你 2020-11-22 09:58

What is export for?

What is the difference between:

export name=value

and

name=value
14条回答
  •  再見小時候
    2020-11-22 10:51

    Just to show the difference between an exported variable being in the environment (env) and a non-exported variable not being in the environment:

    If I do this:

    $ MYNAME=Fred
    $ export OURNAME=Jim
    

    then only $OURNAME appears in the env. The variable $MYNAME is not in the env.

    $ env | grep NAME
    OURNAME=Jim
    

    but the variable $MYNAME does exist in the shell

    $ echo $MYNAME
    Fred
    

提交回复
热议问题