Question 590
Which Linux principle best explains this observation: A shell script prints an updated working directory but the parent terminal remains unchanged?
Explanation
Correct Answer
This behavior is explained by A normally executed script runs in its own process and cannot change its parent's directory. Resolve it through Source a trusted directory-changing script when the intended change must affect the caller and demonstrate that pwd in the invoking terminal reports the intended directory after sourcing.
Incorrect Answers
This option serves the scenario “A Bash function in a profile must be available to the current shell without logging out”. Here, Sourcing executes shell commands in the current environment rather than a separate process. The present scenario is distinguished by “A normally executed script runs in its own process and cannot change its parent's directory”.
The proposed principle does not identify the crucial dependency in this case: A normally executed script runs in its own process and cannot change its parent's directory.
The related but distinct situation is “An automation job needs a temporary locale change without modifying global server defaults”. The relevant Linux mechanism is A variable assignment preceding a command can affect just that command's environment. For the stated problem, “A normally executed script runs in its own process and cannot change its parent's directory” addresses the central condition.