Shell Variables and the Process Environment
A shell can hold local variables. An exported variable can be passed to commands the shell starts, as specified by the shell.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a fresh child
A report may use an exported locale or output directory setting. A variable used only inside the shell script need not appear in the report process. Build environment layers describe how such settings can affect later work.
Keep observation time clear
A child typically receives an environment when launched. Changing a parent setting afterward does not update that running child's copy. A process lifetime identifies which instance receives which settings.[1]
Trace one setting from shell state to a launched program
In a POSIX shell, a variable assigned locally might be visible to shell expansions while absent from a child program's environment. Exporting it or applying an invocation-scoped assignment can pass it to a child. See environment variable layers in builds.
Shell local variable available to shell expression
Exported variable available to subsequently launched child
Child changing its copy leaves the parent's environment in place
Distinguish absence from an empty string
A child reading a variable may use a default only when it is absent. Test with a value, an explicit empty string and an unset environment. Print effective non-sensitive settings when debugging.