zsh-users
 help / color / mirror / code / Atom feed
From: ZyX <kp-pav@yandex.ru>
To: Kurtis Rader <krader@skepticism.us>
Cc: Zsh Users <zsh-users@zsh.org>, Ray Andrews <rayandrews@eastlink.ca>
Subject: Re: grammar triviality with '&&'
Date: Wed, 04 Mar 2015 22:07:32 +0300	[thread overview]
Message-ID: <4572711425496052@web9o.yandex.ru> (raw)
In-Reply-To: <CABx2=D8FCUQjoR7+6k9WBO3rU97tnJMFnpib5YMG1Sqcia=gew@mail.gmail.com>

03.03.2015, 07:44, "Kurtis Rader" <krader@skepticism.us>:
> On Mon, Mar 2, 2015 at 8:15 PM, ZyX <kp-pav@yandex.ru> wrote:
>>  I do not think this is a mistake. And I found at least two differences:
>>
>>  1. `command test --help` returns zero, `command \[ --help` displays help.
>>  2. `[` requires `]` (unless it received `--help` or `--version`), no
>>  matter what name it is called with, `test` requires not.
>>
>>  Note that coreutils ebuild does *not* contain any references to `test` or
>>  `[`, patches as well do not (except when Makefile is patched not to
>>  regenerate man pages). This means that this difference is created by GNU
>>  developers, *not* by distro maintainers.
>
> Ugh! I can confirm your observations using my Ubuntu 14.04 server. Yet on
> Mac OS X Yosemite the two names are linked to the same binary. Mac OS X
> exhibits the traditional behavior. I have no idea why GNU based distros
> have the two names linked to slightly differently behaving binaries.
> Presumably the GNU team had a good reason for this departure from the
> traditional behavior. Furthermore, the GNU team could have used a single
> binary for both names since a program can easily use the name it was
> invoked by to alter its behavior. But that difference doesn't affect my
> point that traditionally /bin/test and /bin/[ referred to the same program
> and /bin/sh didn't know how to do anything other than invoke an external
> command with a sequence of "words" and evaluate its exit status. So "if [
> some condition ]; then" was really just "if /bin/[ some condition \] ;
> then".

If you want `test` and `[` point to the same executable on Gentoo you can compile coreutils with USE=multicall. According to the description this will make *all* programs from coreutils package be compiled into a single executable.

Other than that these programs have different behavior (required by the standard according to Vincent Lefevre). The only possible purpose for making them point to one executable with this remark is saving space*. But this is the case for USE=multicall (its purpose is explained directly in USE flag description).

* I would actually try to refactor this into 2 executables + library, but after reading ldd output for a few coreutils executables it now looks like coreutils developers thought that the least amount of linked libraries is the best option. As long as test and [ live in one repository this does not affect code reusage at all.

>
> Note that quoting is critical. Which is the main reason the Korn-shell
> (ksh) introduced the "[[ ... ]]" syntax. Invoking /bin/[ (or /usr/bin/[)
> requires a trailing "]". Invoking /bin/test (or /usr/bin/test) requires
> that there be no trailing "]". How the arguments are passed to the two
> commands is also important. The "/bin/[" form requires that the shell has
> already tokenized the condition into words.
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank


  parent reply	other threads:[~2015-03-04 19:18 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-01 16:07 Ray Andrews
2015-03-01 16:43 ` ZyX
2015-03-01 17:01   ` Ray Andrews
2015-03-01 18:48     ` Bart Schaefer
2015-03-01 19:00       ` ZyX
2015-03-01 19:16       ` Ray Andrews
2015-03-01 20:48         ` ZyX
2015-03-01 18:49     ` Lawrence Velázquez
2015-03-02  2:27       ` Vincent Lefevre
2015-03-02  3:12         ` Ray Andrews
2015-03-02  5:22           ` Lawrence Velázquez
2015-03-02  3:53         ` Kurtis Rader
2015-03-02  4:18           ` Ray Andrews
2015-03-02  5:22             ` Kurtis Rader
2015-03-02 16:17               ` Ray Andrews
2015-03-02 18:52                 ` Kurtis Rader
2015-03-02 19:03                   ` ZyX
2015-03-02 20:16                     ` Kurtis Rader
2015-03-03  4:15                       ` ZyX
2015-03-03  4:43                         ` Kurtis Rader
2015-03-04 15:03                           ` Vincent Lefevre
2015-03-04 19:07                           ` ZyX [this message]
2015-03-02 19:25                   ` Ray Andrews
2015-03-02 10:46           ` Vincent Lefevre
2015-03-02 11:06             ` Peter Stephenson
2015-03-02 19:19               ` Bart Schaefer
2015-03-04 14:47                 ` Vincent Lefevre
2015-03-05  1:51                   ` Bart Schaefer
2015-03-05 10:06                     ` Peter Stephenson
2015-03-02  8:54         ` Bart Schaefer
2015-03-02 10:31           ` Vincent Lefevre
2015-03-02 16:31             ` Ray Andrews
2015-03-02 16:49             ` Bart Schaefer
2015-03-02 17:38               ` Ray Andrews
2015-03-02 18:51                 ` Bart Schaefer
2015-03-04  8:55               ` Vincent Lefevre
2015-03-04 17:12                 ` Ray Andrews
2015-03-06  4:59                   ` Bart Schaefer
2015-03-06 16:10                     ` Ray Andrews
2015-03-06 20:23                       ` Lawrence Velázquez
2015-03-06 21:25                         ` Ray Andrews
2015-03-06 16:32                     ` Vincent Lefevre
2015-03-06 17:43                       ` Bart Schaefer
2015-03-06 21:01                         ` Ray Andrews
2015-03-09 11:26                         ` Vincent Lefevre

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=4572711425496052@web9o.yandex.ru \
    --to=kp-pav@yandex.ru \
    --cc=krader@skepticism.us \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@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).