zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: 'emulate sh -c' and $0
Date: Thu, 29 May 2014 20:45:33 -0700	[thread overview]
Message-ID: <140529204533.ZM5362@torch.brasslantern.com> (raw)
In-Reply-To: <5387BD0D.8090202@bbn.com>

On May 29,  7:04pm, Richard Hansen wrote:
}
} I just encountered what I think is a bug in Zsh 5.0.5.

To the extent that it's working exactly as documented, it's not a bug ...

}     zsh -c '
}         emulate sh -c "echo \"\$0\""
}         bar() { emulate sh -c "echo \"\$0\""; }
}         bar
}     ' foo arg1
} 
} I expected it to produce:
} 
}     foo
}     foo

If you throw in "unsetopt functionargzero" any time before calling "bar" 
then it does produce that output.

If you rewrite your example as

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

then it also produces your expected output; you just need to define the
function in the right scope.

} 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.

I don't find those examples particularly compelling, but the original
value of $0 is already stashed; what would need to change is that the
*local* value of $0 gets temporarily replaced by the global one.  (The
[un]setting of functionargzero controls whether a local value is ever
created in the first place.)


  reply	other threads:[~2014-05-30  3:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-29 23:04 Richard Hansen
2014-05-30  3:45 ` Bart Schaefer [this message]
2014-05-30  8:49   ` Richard Hansen
2014-05-30 17:00     ` Bart Schaefer
2014-05-30 21:14       ` Richard Hansen
2014-05-31  5:13         ` Bart Schaefer
2014-05-31 23:47           ` Bart Schaefer
2014-06-03 20:15           ` Richard Hansen
2014-06-03 20:26             ` Peter Stephenson
2014-06-03 21:10               ` Bart Schaefer
2014-06-03 23:35                 ` Richard Hansen
2014-06-04  0:09                   ` Bart Schaefer
2014-06-03 21:21             ` Bart Schaefer
2014-06-03 22:54               ` Richard Hansen
2014-06-04  0:03                 ` Bart Schaefer
2014-06-04  1:10                   ` Bart Schaefer
2014-06-04  1:23                 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140529204533.ZM5362@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).