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

'emulate sh -c' and $0



Hi all,

I just encountered what I think is a bug in Zsh 5.0.5.  The following
command:

    zsh -c '
        emulate sh -c "echo \"\$0\""
        bar() { emulate sh -c "echo \"\$0\""; }
        bar
    ' foo arg1

produces the following output:

    foo
    bar

I expected it to produce:

    foo
    foo

This is relevant when sourcing a file containing (POSIX) sh code that
might examine $0 (e.g., for logging or to 'exec "$0" "$@"' after
exporting/unsetting environment variables).

Perhaps Zsh should save the original value of $0 somewhere and restore
it when entering sh emulation mode.

Thanks,
Richard



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