Changes in a Shell and in Its Child Processes

A child normally receives an inherited environment and starting directory. Changing those settings in the child does not normally change the parent's environment.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a subcommand
  2. Identify built-in operations
  3. Follow a working-directory change across the process boundary
  4. Check which changes callers are supposed to observe

Trace a subcommand

A child helper can change to the data folder for its own work. Once it exits, the invoking shell still resolves relative paths from its earlier base. See working directories.

Identify built-in operations

A shell's own directory-changing command changes that shell's environment. Whether a command runs in the shell, a subshell, or a child depends on the invocation. Working tree settings are easier to reproduce when these scopes are clear.[1]

Follow a working-directory change across the process boundary

A helper launched as a child can change its own working directory. The caller's directory does not change simply because that child exited. A shell operation evaluated in the current shell can instead modify the caller's state. See the shell working directory.

Parent working directory: /work
Child changes to /work/tmp, uses child-local state
Child exits
Parent working directory remains /work

Check which changes callers are supposed to observe

A command can intentionally return data for a parent to use. Files can also persist across processes. Distinguish those effects from changes to process-local variables and directories. Test the state before and after invocation.

References

  1. The Open Group, POSIX Shell Command Language ↩