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

Re: Best practices for managing aliases in ohmyzsh?



On Wed, Sep 1, 2021, at 4:03 PM, Bart Schaefer wrote:
> On Wed, Sep 1, 2021 at 12:56 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> > What if you source a file with another shell's shebang?

Even before getting to language mismatches, it generally doesn't
make sense to source a file that has a shebang because such a file
probably assumes that it'll be run in a separate process.  For
instance, it might create a lot of temporary variables or utility
functions and not clean any of it up.

Similarly, I don't think you should include a shebang in a file
that is not meant to be executed by a separate interpreter because
that is the whole point of shebangs.  Including one sends a strong
signal that that file is supposed to be executed.

> Sufficiently portably written shell code might work, and there are
> some tricks you can do in some languages that have superficial
> similarities so that incorrect interpreters can recognize themselves
> and do a backflip, but for the most part it is indeed "barf."

Observe:

    % cat ./barf.py 
    #!/usr/bin/python

    import sys
    print(sys.argv)

    % chmod +x ./barf.py 

    % ./barf.py 1 2 3
    ['./barf.py', '1', '2', '3']

    % . ./barf.py
    ./barf.py:3: command not found: import
    ./barf.py:4: unknown file attribute: y


-- 
vq




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