zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Cc: Bart Schaefer <schaefer@brasslantern.com>
Subject: Re: Is "command" working right, yet?
Date: Sun, 07 Feb 2016 15:24:40 +0000	[thread overview]
Message-ID: <56B761B8.6000507@inlv.org> (raw)
In-Reply-To: <160202163744.ZM2066@torch.brasslantern.com>

Bart Schaefer schreef op 03-02-16 om 00:37:
[...]
> burner% setopt posixbuiltins
> burner% command -p -V true
> zsh: command not found: -V
> burner% command -V -p true  
> command: bad option: -p
> 
> I think this is pretty clearly a bug.

Agreed, these options should combine without a problem.

> Using the versions available on my Ubuntu desktop, and default $PATH, all
> of bash, ksh, and zsh with POSIX_BUILTINS, execute the builtin for both
> "command" and "command -p".

The same for dash, pdksh/mksh and yash.

> Anybody know if that's correct?

I believe so. Normally, builtins are searched for $PATH. The spec for
'command -p'[*] says the command is executed with a default $PATH that
is guaranteed to find all of the standard utilities, but not that
builtins aren't searched first as usual. According to POSIX, builtins
are supposed to be standard commands equivalent to their external
correspondents, so in theory it shouldn't make any difference.

> If it is, how does one force the use of the external command in [the
> forthcoming] POSIX?

The only way I know of is to run it with an explicit path, such as
/bin/echo hi

To find out the path of an external command without considering
builtins, there is 'which' on most systems, but it is not POSIX. I don't
know of any current system without it, though.

For 100% cross-platform compatibility guarantee, it is not too hard to
write a shell function that finds the absolute path of a command. I
wrote this once for an installer that is compatible with the original
Bourne shell as well as POSIX:

# Output the first path of each given command, or, if given -a, all possible
# paths, in the given order, according to the system $PATH. Like BSD
'which'.
# Returns successfully if at least one path was found, unsuccessfully if
not.
# This abridged function ignores paths (as in 'which /bin/ls').
which() { (
    unset opt_allpaths flag_somenotfound
    IFS=':'  # separator in $PATH
    test "$1" = '-a' && opt_allpaths='y' && shift
    for arg do
        unset flag_foundthisone
        cmd=`basename $arg`
        for dir in $PATH; do  # for native zsh, you want ${=PATH}
            if test -f "$dir/$cmd" -a -x "$dir/$cmd"; then
                flag_foundthisone='y'
                printf '%s/%s\n' "$dir" "$cmd"
                test -z "$opt_allpaths" && break
            fi
        done
        test -n "$flag_foundthisone" || flag_somenotfound=y
    done
    test -z "$flag_somenotfound"
); }

- M.

[*]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html#tag_20_22_04


  reply	other threads:[~2016-02-07 15:24 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 [this message]
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
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=56B761B8.6000507@inlv.org \
    --to=martijn@inlv.org \
    --cc=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).