In most shells, $VAR
and $var
and $Var
are three different variables because the shell (all that >> I << am aware of) is case sensitive.
In zsh
on MacOS 13.01:
[Start a fresh copy of zsh]
% s=tst
% S="something else"
% echo "\$s=$s"
$s=tst
% echo "\$S=$S"
$S=something else
% [[ "$s" == "$S" ]] || echo "Not equal"
Not equal
However, in zsh
on MacOS, examine $PATH
and $path
:
% echo $PATH
/Users/dawg/perl5/bin:/usr/local/opt/ruby/bin:/usr/local/opt/python@3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
% echo $path
/Users/dawg/perl5/bin /usr/local/opt/ruby/bin /usr/local/opt/python@3.10/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin
It appears that $path
is a space delimited version of $PATH
.
Now change PATH
in the typical way:
% export PATH=/some/new/folder:$PATH
% echo $PATH
/some/new/folder:/Users/dawg/perl5/bin:/usr/local/opt/ruby/bin:/usr/local/opt/python@3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
That is what I expect, but it also changes $path
:
% echo $path
/some/new/folder /Users/dawg/perl5/bin /usr/local/opt/ruby/bin /usr/local/opt/python@3.10/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin
WORSE, changing $path
also changes $PATH
!
This is not the same in a brew
install of Bash which has no secret $path
waiting to bite.
It bit me (with an hour of head scratching) with a loop like this on zsh on MacOS:
for path in **/*.txt; do
# do some things with sys utilities with $path...
# sys utilities like awk in the PATH were not found
done
Questions:
- Is the
$PATH
/$path
link documented somewhere? - What is the purpose?
- How do I turn this off??
- Why would Apple do this???