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

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



Hello,

Yesterday I stumbled upon a bug where setting $PATH when emulating
sh would would break the variable synchronization between the string
($PATH) and the array ($path):
--8<---------------cut here---------------start------------->8---
$ echo $PATH
/gnu/store/j1jv0f6cs18s76jbkp8h7nbh1i7rwgz2-profile/bin:/home/bricewge/.zsh/polaris/sbin:/home/bricewge/.zsh/polaris/bin:/home/bricewge/.zsh/polaris/usr/sbin:/home/bricewge/.zsh/polaris/usr/bin:/home/bricewge/misc/go/bin:/home/bricewge/.emacs.d/bin:/home/bricewge/.local/bin:/run/setuid-programs:/home/bricewge/.config/guix/current/bin:/home/bricewge/.guix-profile/bin:/home/bricewge/.guix-profile/sbin:/run/current-system/profile/bin:/run/current-system/profile/sbin
$ echo $path
/gnu/store/j1jv0f6cs18s76jbkp8h7nbh1i7rwgz2-profile/bin /home/bricewge/.zsh/polaris/sbin /home/bricewge/.zsh/polaris/bin /home/bricewge/.zsh/polaris/usr/sbin /home/bricewge/.zsh/polaris/usr/bin /home/bricewge/misc/go/bin /home/bricewge/.emacs.d/bin /home/bricewge/.local/bin /run/setuid-programs /home/bricewge/.config/guix/current/bin /home/bricewge/.guix-profile/bin /home/bricewge/.guix-profile/sbin /run/current-system/profile/bin /run/current-system/profile/sbin
$ 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
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---

Cheers,
- Brice




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