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

Re: NOMATCH errors



On 01/05/2017 10:35 PM, Anthony Heading wrote:
> Hi,
> 
> I was dusting off an old script which, admittedly inelegantly, did
>   PYTHON==python 2>/dev/null
> with NOMATCH set, which in the zsh 5 era seems to be a fatal error, i.e.
> a script

> 
> So I was wondering the cleanest way to do this.  `which python` is the
> old-school
> way, I guess, but the documentation isn't very reassuring about output
> format

> Any thoughts appreciated,  especially if I'm missing a neat way to do
> this.
> 
> Thanks
> 
> Anthony

zsh already hashes commands at startup, you can access that entry
with $commands[python]. Since what =python would resolve
to already hashed, just calling python is fine.

Unless the script installs python or an additional `python',
in the former case zsh will notice python isn't in the command hash
table, add it and run the command, all during the first time the script
calls python. In the latter case, if the additional
`python' binary is early in PATH and you want to use it, running
''rehash python'' would hash it.

If the point of PYTHON==python was just to use $PYTHON in place of
just python under the guise of "always use the absolute paths to
commands to prevent future PATH lookups" advise some people spout, it's
pretty superfluous since zsh already hashed the command and won't do
another PATH lookup unless you use rehash (hash -r) or =python.



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