From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22828 invoked from network); 21 Aug 2020 13:03:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Aug 2020 13:03:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From: Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=FicNdtn/jZst+8+WlhaBiiVdx/INLjvnSbEJafAwbHY=; b=jdcZaVMENkkRhSRwZ1aXC960TS BCOXd50ASGgR5egwRT0MPWILv7Zo8eH4Vx424bNIomx7k66WSvSGgKzGmApqVW1l4v9rWmSnyBzp9 zQNHGX4TDTTYGdY6zt+E2QOX6c+AacPbLiLfIq9uTvpTPyTnnSFvyRT8GUEgXDRUl34ua8TElwMlP /rXQuEMYuNqmW9GOcBsxpiZ/swuaBzQ5EjQeVipWStm0fv2x25Fk1hig5c3Vd4VPJ2sWGcqhpSgNe x6Ks23HAAF8Hhhv2QQpCMxRc1ipLWOc5c6OrioKKOd8QA7SJNzPQqm5uleYFe5dSM6eig8yIqfi/j KY+ARa9g==; Received: from authenticated user by zero.zsh.org with local id 1k96hw-000Lpw-Aa; Fri, 21 Aug 2020 13:03:48 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=skipped; arc=none Received: from smtpq2.tb.ukmail.iss.as9143.net ([212.54.57.97]:45250) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1k96hd-000Lgx-8s; Fri, 21 Aug 2020 13:03:30 +0000 Received: from [212.54.57.80] (helo=smtp1.tb.ukmail.iss.as9143.net) by smtpq2.tb.ukmail.iss.as9143.net with esmtp (Exim 4.86_2) (envelope-from ) id 1k96hb-0002Fu-U0 for zsh-workers@zsh.org; Fri, 21 Aug 2020 15:03:27 +0200 Received: from oxbe24.tb.ukmail.iss.as9143.net ([172.25.160.155]) by smtp1.tb.ukmail.iss.as9143.net with ESMTP id 96hbk1AGddIiK96hbkNxQ1; Fri, 21 Aug 2020 15:03:27 +0200 X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-workers@zsh.org X-SourceIP: 172.25.160.155 X-CNFS-Analysis: v=2.4 cv=Hs/Ip2fS c=1 sm=1 tr=0 ts=5f3fc61f a=7eg3RIOFpSGgz8rG3xBEDw==:117 a=KEnZaF_ea6UA:10 a=IkcTkHD0fZMA:10 a=DoY9bV0jb9AA:10 a=YR4_K0clAAAA:8 a=uZvujYp8AAAA:8 a=zB_PqkWPOJU5pF9scmgA:9 a=WaLqzWMx2QtT5RtJ:21 a=URxL03DcRzV2Qu7h:21 a=QEXdDO2ut3YA:10 a=DQuAP32-rjYA:10 a=waMAY2KAzxQUlx2gRwsv:22 a=SLzB8X_8jTLwj6mN0q5r:22 X-Authenticated-Sender: p.w.stephenson@ntlworld.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com; s=meg.feb2017; t=1598015007; bh=SDMh+6f9zJ2940FARViJssHSkXrQrrW1El/8sstbTKo=; h=Date:From:To:In-Reply-To:References:Subject; b=QM+pgrCAGSNmXf4avk5MqRhBnx9tgm+ca5UmCl0ikoMehbGEDigNc1OmOmJhOK5jo 0qS0Ni6oH282qUJ9aGb8YvNhVjCWgGYT4tafRe0CysGmCtnF4HxRz0bmdhg2wvH8es TXZpcEYmId5wDwROLyqpQbWwBoyw9yO5A10LGfbWJw/wRi+po9XJ0Js0PkJytNNGYG HP3Feaq2VAkATLMtyVuavmhq0cCUsF8mTTGDKKG2E7lID22DK3km0c4wYBje3MK54D /1624b5+2s/SNtARx+eeA4rB/WzLwCRiBUM1RPiUglLUHO8q+IOLP6srL+dlHHMVgq PDJNYkGXuUZTQ== Date: Fri, 21 Aug 2020 14:03:27 +0100 (BST) From: Peter Stephenson To: zsh-workers@zsh.org Message-ID: <1194318329.1319677.1598015007835@mail2.virginmedia.com> In-Reply-To: <20200820112815.GA216072@zira.vinc17.org> References: <20200820112815.GA216072@zira.vinc17.org> Subject: Re: command -p should enable builtins not in path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.4-Rev72 X-Originating-IP: 165.225.81.56 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4xfPs+pI061RtewdOE2vy0pbR8wQ740bmdd5ccHTs6+0fA7P0EowOmmQ3VltQ/TCxCL7ndy5RMURLejbVOqq5SOagbsht4ghownKvNOTeZrX4hAUpITftM Ho1PB8u4rOOKIhxYTpY8TFql8HkvrjjQX0JuUSzcz50rryvPLnuXuwrQhDw78UEuEVj1/Q/ujQej53vdWfsJxImRFYvQwrBASJxiJfdNmed05S8wYbL2uuTN X-Seq: 47331 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: > On 20 August 2020 at 12:28 Vincent Lefevre wrote: > > > 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: I tend to agree there's not a lot of point in this incompatibility, given where the "-p" flag originates --- it's a relatively late addition to zsh. Here's one possible fix. pws diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 4b91db1fe..17ebba2ac 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -318,10 +318,15 @@ item(tt(command) [ tt(-pvV) ] var(simple command))( The simple command argument is taken as an external command instead of a function or builtin and is executed. If the tt(POSIX_BUILTINS) option is set, builtins will also be executed but certain special properties -of them are suppressed. The tt(-p) flag causes a default path to be -searched instead of that in tt($path). With the tt(-v) flag, tt(command) -is similar to tt(whence) and with tt(-V), it is equivalent to tt(whence --v). +of them are suppressed. + +The tt(-p) flag causes a default path to be searched instead of that in +tt($path). The intention of the option is that all standard commands +may be found, so builtins are also checked, but not other types of +command such as functions. + +With the tt(-v) flag, tt(command) is similar to tt(whence) and with +tt(-V), it is equivalent to tt(whence -v). See also ifzman(the section `Precommand Modifiers' in zmanref(zshmisc))\ ifnzman(noderef(Precommand Modifiers)). diff --git a/Src/exec.c b/Src/exec.c index ecad923de..f18513703 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3165,8 +3165,19 @@ execcmd_exec(Estate state, Execcmd_params eparams, } } hn = NULL; - if ((cflags & BINF_COMMAND) && unset(POSIXBUILTINS)) + if ((cflags & BINF_COMMAND) && unset(POSIXBUILTINS)) { + if (use_defpath && nonempty(preargs)) { + /* + * command -p can find builtins as these are + * in a standard location. So check. + */ + if ((hn = builtintab->getnode(builtintab, + (char *) peekfirst(preargs)))) { + checked = is_builtin = 1; + } + } break; + } if (!nonempty(preargs)) execcmd_getargs(preargs, args, eparams->htok); } diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index 35a04e7d5..e62fb531b 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -200,6 +200,17 @@ >cat is /*/cat >echo is a shell builtin + (mkdir testdir_for_command-p + command -p cd testdir_for_command-p + print ${PWD##*/}) +0:command -p finds builtins +>testdir_for_command-p + + func_not_searched() { This was not found; } + command -p func_not_searched +127:command -p does not find functions +?(eval):2: command not found: func_not_searched + cd() { echo Not cd at all; } builtin cd . && unfunction cd 0:`builtin' precommand modifier