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

Re: Best practices for managing aliases in ohmyzsh?



On Tue, Aug 31, 2021 at 7:33 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Yikes, I'm missing something fundamental.  In my head, executing a
> script is identical to sourcing it.  It's not a binary, so what else can
> there be than interpreting the file?

The file typically names the interpreter that will understand it.
That's the point of the shebang (#!) line at the top of the file.

Thus you can have zsh scripts, bash scripts, perl scripts, python
scripts, etc. and the shell (or some other program) that wants to run
the script doesn't have to be the same one that understands the
scripts.  It just says "execute this" and the operating system looks
at the #! and starts up (a new invocation of) the correct program.
That new copy "sources" the file.

The context of the discussion has been (1) how to zsh interactively
but run scripts written for bash, without having to convert them, and
(2) how to make all those scripts accessible to zsh without having to
predefine them somehow in .zshrc.  The answer is to make them
executable and put bash in the #! line, so that bash continues to be
what runs them.  That works as long as what the script does, does not
need to persist in the interactive zsh (see "new invocation" above).




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