zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Is "command" working right, yet?
Date: Tue, 27 Sep 2016 13:15:23 +0100	[thread overview]
Message-ID: <564b0585-4286-a6c6-d64e-b190af5ace57@inlv.org> (raw)
In-Reply-To: <20160927110820.7661e8ad@pwslap01u.europe.root.pri>

Op 27-09-16 om 11:08 schreef Peter Stephenson:
> On Sun, 25 Sep 2016 20:13:28 -0700
> Bart Schaefer <schaefer@brasslantern.com> wrote:
>> A complication is that "command -v" is defined in terms of bin_whence(),
>> and "whence" has a -p option that means something different.
> 
> That also means path search.

Nope.

'command -p' means: ignore the PATH environment variable and do the
search as normal, but (if it's a path search) use the system default
path as output by the 'getconf PATH' command. That means the -p option
has no effect for builtins.

POSIX provides this as one way to make shell scripts a bit more robust;
'command -p grep' guarantees you get either the system's external 'grep'
or a builtin version provided by the shell, and not some other 'grep'
that the user (or someone who hacked them) may have installed in some
location that comes before the real 'grep' in $PATH and that may, for
all anyone knows, delete all their files.

Reference:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html#tag_20_22_04

This is why it's important that '-p' should combine properly with '-v'
and '-V'. The command 'command -pv grep', provided there is no builtin
for it, should output the location of the system default 'grep' as
opposed to whatever 'grep' may take precedence over it in $PATH.

By the way, 'command -p' *nearly* works properly (i.e. as described
above) in zsh, apart from combining with other options. See line 664 and
on in exec.c, line 2030 and on in configure.ac, and line 77 in config.h.in.

The problem is configure.ac only tries non-standard 'getconf' commands
(i.e. 'getconf _CS_PATH' and 'getconf CS_PATH'); the command to use on
BSD/OSX is 'getconf PATH', which works on Linux as well. I don't know if
the other two should be kept, but 'getconf PATH' should at least be added.

diff --git a/configure.ac b/configure.ac
index 0e0bd53..e0eb320 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2035,6 +2035,8 @@ AC_CACHE_VAL(zsh_cv_cs_path,
   zsh_cv_cs_path=`getconf _CS_PATH`
 elif getconf CS_PATH >/dev/null 2>&1; then
   zsh_cv_cs_path=`getconf CS_PATH`
+elif getconf PATH >/dev/null 2>&1; then
+  zsh_cv_cs_path=`getconf PATH`
 else
   zsh_cv_cs_path="/bin:/usr/bin"
 fi])


Thanks,

- M.


  reply	other threads:[~2016-09-27 12:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03  0:37 Bart Schaefer
2016-02-07 15:24 ` Martijn Dekker
2016-09-25 23:31   ` Martijn Dekker
2016-09-26  3:13     ` Bart Schaefer
2016-09-26 10:56       ` Martijn Dekker
2016-09-26 17:02         ` Bart Schaefer
2016-09-27 10:08       ` Peter Stephenson
2016-09-27 12:15         ` Martijn Dekker [this message]
2016-09-28 10:30           ` Peter Stephenson
2016-09-28 18:37             ` Martijn Dekker
2016-09-29  8:55               ` Peter Stephenson
2016-10-11 13:40                 ` Martijn Dekker
2016-10-11 13:56                   ` Peter Stephenson
2016-10-11 16:20                     ` Martijn Dekker
2016-10-20 12:44                       ` Peter Stephenson
2016-10-20 13:06                         ` Peter Stephenson

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=564b0585-4286-a6c6-d64e-b190af5ace57@inlv.org \
    --to=martijn@inlv.org \
    --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).