Defining a variable with or without export

后端 未结 14 1657
借酒劲吻你
借酒劲吻你 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:40

    The accepted answer implies this, but I'd like to make explicit the connection to shell builtins:

    As mentioned already, export will make a variable available to both the shell and children. If export is not used, the variable will only be available in the shell, and only shell builtins can access it.

    That is,

    tango=3
    env | grep tango # prints nothing, since env is a child process
    set | grep tango # prints tango=3 - "type set" shows `set` is a shell builtin
    

提交回复
热议问题