Defining a variable with or without export

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

    Two of the creators of UNIX, Brian Kernighan and Rob Pike, explain this in their book "The UNIX Programming Environment". Google for the title and you'll easily find a pdf version.

    They address shell variables in section 3.6, and focus on the use of the export command at the end of that section:

    When you want to make the value of a variable accessible in sub-shells, the shell's export command should be used. (You might think about why there is no way to export the value of a variable from a sub-shell to its parent).

提交回复
热议问题