Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Best practices for managing aliases in ohmyzsh?



On 2021-09-01 12:16 p.m., Bart Schaefer wrote:
No, you're still misunderstanding (or making typos). A sourced script
DOES NOT create its own fresh environment, it affects the environment
of the program that sources it.

But ... don't I recall that a script runs in a separate process? Doing some quick looking (zsh is the same I trust):


     Bash scripts are not kept in the shell’s memory. *Whenever a
     script is executed, a new subshell (non-interactive shell) is
     forked to execute the script.* And within the subshell, the script
     is executed by the interpreter specified in the shebang line
     <https://www.baeldung.com/linux/shebang> (for example,
     /#!/bin/bash/). But, if required, we can also execute the script
     within the current shell using the /source/ command.

(think, think, think ... )

Ok, I was too flabby in interpreting 'execute'.  I've taken 'source' to be identical to 'execute'.  Not so.  But ... what if you have a shebang in a sourced file?  One might suppose that forces a subshell, no?  Everything I write has the shebang, I just put it there every time.  What if you source a file with another shell's shebang?  Possible paradox there.  It would *have* to run the other shell in a subshell unavoidably there -- or just barf.









Messages sorted by: Reverse Date, Date, Thread, Author