Le 11/18/24 à 11:50, to...@tuxteam.de a écrit :

Help yourseof :)

  https://sources.debian.org/src/coreutils/

(Of course, apt-get source coreutils would do the same).

Cheers


Thank you tomas,

After a second reading of 
https://sources.debian.org/src/coreutils/9.5-1/src/test.c/,
it seems that the [ binary, the [ shell builtin and the test command all share 
the same C source code  (test.c)
which has different #ifdef branches to handle all three outputs.


#define TEST_STANDALONE 1

this ensures that code for the test binary is executed,
otherwise it produces the test shell builtin (somehow?)


#ifndef LBRACKET
# define LBRACKET 0
#endif

/* The official name of this program (e.g., no 'g' prefix).  */
#if LBRACKET
# define PROGRAM_NAME "["
#else
# define PROGRAM_NAME "test"
#endif


That creates the appropriate program name,
depending on wether we want [ or not.


  if (LBRACKET)
    {
      /* Recognize --help or --version, but only when invoked in the
         "[" form, when the last argument is not "]".  Use direct
         parsing, rather than parse_long_options, to avoid accepting
         abbreviations.  POSIX allows "[ --help" and "[ --version" to
         have the usual GNU behavior, but it requires "test --help"
         and "test --version" to exit silently with status 0.  */
      if (margc == 2)
        {
          if (STREQ (margv[1], "--help"))
            usage (EXIT_SUCCESS);

          if (STREQ (margv[1], "--version"))
            {
              version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
                           (char *) nullptr);
              test_main_return (EXIT_SUCCESS);
            }
        }
      if (margc < 2 || !STREQ (margv[margc - 1], "]"))
        test_syntax_error (_("missing %s"), quote ("]"));

      --margc;
    }


That seems to be the code that looks for the closing bracket,
if test is invoked as [


So it seems [ is created with a -DLBRACKET option.

Best,


--
yassine -- sysadm
http://about.me/ychaouche

Reply via email to