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

Re: PATH variable case-insensitive?



05.02.2015, 19:10, "Koch" <omgoch@xxxxxxxxx>:
> Using zsh 5.0.2 (x86_64-pc-linux-gnu) with the following file contents in
> ./test.zsh:
>
> PATH=bar
> path=omg
> echo $PATH
>
> and running zsh ./test.zsh outputs:
> omg
>
> Is this a bug? It's certainly not my intention to have this meaning attached to
> this program, since it goes against POSIX.

If you want  POSIX emulation in zsh, do use either `emulate -L sh` at the top of the script or run it with symlink named sh (i.e. rather use `sh` as the last component of the program name*)`.

Strict POSIX compatibility was never a goal of zsh in its “native” mode. For interactive uses this feature is rather convenient. In scripts I myself have run several times into the effective inability to use `path` variable in e.g. `for path in foo/*` until learned this thing though.

* Like this with execve, see the beginning of execve argument:

        % echo 'int main(int argc, char **argv, char **environ) { execve("/bin/zsh", (const char *[]) {"/bin/sh", "-c", "echo path:$path PATH:$PATH", 0}, environ); }' | tcc -run -
        path: PATH:/bin:/usr/bin:/usr/ucb:/usr/local/bin
        % echo 'int main(int argc, char **argv, char **environ) { execve("/bin/zsh", (const char *[]) {"/bin/zsh", "-c", "echo path:$path PATH:$PATH", 0}, environ); }' | tcc -run 
        path:/bin /usr/bin /usr/ucb /usr/local/bin PATH:/bin:/usr/bin:/usr/ucb:/usr/local/bin

  (It actually appears that tcc does not support 3-argument form of main() (this is not my actual $PATH setting). But the point can be seen in any case since shell is able to get $PATH setting somewhere. Use `gcc -xc - && ./a.out && rm ./a.out` in place of `tcc -run -` to see your actual $PATH setting.)



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