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

Re: emulate -L sh impact on $0, $argv




31.01.2016, 21:04, "Sebastian Gniazdowski" <sgniazdowski@xxxxxxxxx>:
> Hello
> Is this expected behavior:
>
> % echo 'echo Hello, my 0 is $0, argv0 is ${argv[0]}' > test_file.sh;
> source() { emulate -L zsh; builtin source "$@"; }; source
> ./test_file.sh
> Hello, my 0 is ./test_file.sh, argv0 is
>
> % echo 'echo Hello, my 0 is $0, argv0 is ${argv[0]}' > test_file.sh;
> source() { emulate -L sh; builtin source "$@"; }; source
> ./test_file.sh
> Hello, my 0 is source, argv0 is ./test_file.sh
>
> Sometimes -L zsh gives correct argv[0], couldn't clarify exactly when,
> it may have something to do with reversed order of the calls.

Array indexing starts with one, not zero, so $argv[0] in zsh emulation mode is not what you think: it is empty. *Always*. And in any case has nothing to do with $0, $0 is never present in $argv. Array indexing *may* start with zero, controlled by KSH_ARRAYS option which is again different in zsh and sh emulation mode.

What is contained is $0 is controlled by FUNCTION_ARGZERO option, which is different in zsh and sh modes.

>
> Best regards,
> Sebastian Gniazdowski



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