zsh-workers
 help / color / mirror / code / Atom feed
* command -p should enable builtins not in path
@ 2020-08-20 11:28 Vincent Lefevre
  2020-08-21 13:03 ` Peter Stephenson
  2020-08-21 15:47 ` Martijn Dekker
  0 siblings, 2 replies; 9+ messages in thread
From: Vincent Lefevre @ 2020-08-20 11:28 UTC (permalink / raw)
  To: zsh-workers

Though zsh isn't meant to conform to POSIX, it should follow its
requirements when they make sense.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html

says:

  The following options shall be supported:

  -p
    Perform the command search using a default value for PATH that is
    guaranteed to find all of the standard utilities.
                       ^^^

So, in particular, the standard utility "cd" must be found. Note that
the above sentence does not mean that the utility must be somewhere
in $PATH, just that the used PATH value allows the shell to find the
utility; in case of a builtin utility (like "cd"), this will just run
the utility without needing PATH.

This works with all usual shells, except zsh:

zira% sh -c "command -p cd /tmp; pwd"
/tmp
zira% bash -c "command -p cd /tmp; pwd"
/tmp
zira% ksh -c "command -p cd /tmp; pwd"
/tmp
zira% zsh -c "command -p cd /tmp; pwd"
zsh:1: command not found: cd
/home/vinc17
zira% echo $ZSH_VERSION
5.8

Setting the POSIX_BUILTINS option allows "cd" to be found, but with
the drawback that it will not disable builtins that are in $PATH.
So this option is a bad solution when using "zmodload zsh/files"
without -F, for instance.

Note: "command -p cd ..." is used by Intel's script to set up
environment variables for its compiler.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-10-02 13:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 11:28 command -p should enable builtins not in path Vincent Lefevre
2020-08-21 13:03 ` Peter Stephenson
2020-08-21 15:49   ` Martijn Dekker
2020-08-21 16:08     ` Peter Stephenson
2020-08-21 16:35       ` Martijn Dekker
2020-08-24 18:30     ` Vincent Lefevre
2020-08-24 19:59       ` Martijn Dekker
2020-10-02 13:17         ` Vincent Lefevre
2020-08-21 15:47 ` Martijn Dekker

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