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

Re: [bug] Special parameters $PATH and $path aren't kept in sync after emulating sh



Brice Waegeneire wrote on Mon, 09 Nov 2020 07:27 +00:00:
> $ cat /tmp/test.sh
> unset PATH
> export PATH=/foo
> $ emulate sh -c 'source /tmp/test.sh'
> _direnv_hook:1: command not found: direnv
> $ echo $PATH
> /foo
> $ echo $path
> 
> $ export PATH=bar:baz
> $ echo $PATH
> bar:baz
> $ echo $path
> --8<---------------cut here---------------end--------------->8---
> 
> In effect it overwride my path instead of adding a new entry to it

Your code is not expected to append an entry to $PATH.  To do that,
you'd want to do «PATH="${PATH}:/new/entry"» (plus or minus the «export»
keyword in front).

> when I do it from the array variable ($path) after setting it from
> from the string variable ($PATH). To workaround this issue I have
> found the following to work:
> 
> --8<---------------cut here---------------start------------->8---
> $ tmp="$PATH"
> $ unset PATH
> $ export PATH="$tmp"
> $ unset tmp
> --8<---------------cut here---------------end--------------->8---

This doesn't append either.  (Also, a signal might come in whilst PATH
is undefined in the environment.)




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