Skip to main content
Welcome guest. | Register | Login | Post

/bin/true

16 replies [Last post]
a thing's picture
Offline
Joined: 2005-12-20
$ ls -lh /bin/true
-rwxr-xr-x 1 root root 17K Nov 24 10:40 /bin/true
$ touch true
$ chmod +x true
$ ls -lh true
-rwxr-xr-x 1 notroot notroot 0 Dec 19 18:35 true
$ ./true; echo $?
0
$
free-zombie's picture
Offline
Joined: 2006-03-08
does not work in zsh. looks

does not work in zsh. looks like a feature bug in bash, completely unrelated to Linux.

dylunio's picture
Offline
Joined: 2005-12-20
What does this show, save

What does this show, save that running an empty executable file in bash returns TRUE? Am I just being thick?

dylunio

a thing's picture
Offline
Joined: 2005-12-20
0 is better than 17KB

It shows that /bin/true is bloated.

tbuitenh's picture
Offline
Joined: 2005-12-21
accidentally funny, from

accidentally funny, from the manpage of true:

Quote:

SEE ALSO
The full documentation for true is maintained as a Texinfo manual. If
the info and true programs are properly installed at your site, the
command

info true

should give you access to the complete manual.

dylunio's picture
Offline
Joined: 2005-12-20
It shows...
a thing wrote:

It shows that /bin/true is bloated.

Ah, I see.

free-zombie's picture
Offline
Joined: 2006-03-08
a thing wrote: It shows
a thing wrote:

It shows that /bin/true is bloated.

no, it does not. It shows that /bin/true is larger than an equivalent-for-bash-and-not-all-shells.

However, /bin/true is of course bloated. On my machine /bin/true is 17K, while the following C code compiled is 8.5K (7.4K with -m32, -Os makes no diff):

int main(int argc, char **argv)
{
    return 0;
}

does anybody know x86 assembler ? Eye

dylunio's picture
Offline
Joined: 2005-12-20
Looking at the sourcecode

Looking at the sourcecode for /bin/true it seems that most of the file is stuff on usage and versioning, with the returning of of true being the tiniest part of it.

dylunio

tbuitenh's picture
Offline
Joined: 2005-12-21
That implementation of true

That implementation of true is incomplete, it should have --help and --version options.

free-zombie's picture
Offline
Joined: 2006-03-08
tbuitenh wrote: That
tbuitenh wrote:

That implementation of true is incomplete, it should have --help and --version options.

that can also be seen as bloat.

tbuitenh's picture
Offline
Joined: 2005-12-21
I rewrote true with exactly

I rewrote true with exactly the same version and help information. The information in the source code below is INCORRECT, this is NOT gnu true).

#include <stdio.h>
#include <string.h>

int main(int argc, char ** argv) {
  if (argc == 2) {
    if (!strcmp(argv[1], "--help")) puts(
      "Usage: /bin/true [ignored command line arguments]\n"
      "  or:  /bin/true OPTION\n"
      "Exit with a status code indicating success.\n\n"
      "--help     display this help and exit\n"
      "--version  output version information and exit\n\n"
      "NOTE: your shell may have its own version of true, which usually supersedes\n"
      "the version described here.  Please refer to your shell's documentation\n"
      "for details about the options it supports.\n\n"
      "Report bugs to <bug-coreutils@gnu.org>."
    );
    if (!strcmp(argv[1], "--version")) puts(
      "true (GNU coreutils) 6.7\n"
      "Copyright (C) 2006 Free Software Foundation, Inc.\n"
      "This is free software.  You may redistribute copies of it under the terms of\n"
      "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"
      "There is NO WARRANTY, to the extent permitted by law.\n\n"
      "Written by Jim Meyering."
    );
  }
  return 0;
}

gcc -o true true.c
du -h ./true
8.0K ./true
du -h /bin/true
16K /bin/true

So that is at least 8K of bloat by any definition. Or did I miss some undocumented functionality?

dylunio's picture
Offline
Joined: 2005-12-20
I'm not sure if you've

I'm not sure if you've missed undocumented functionality, but I'll post the true code for GNU's true so people who understand C better than me can judge:

/* Exit with a status code indicating success.
   Copyright (C) 1999-2003, 2005 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#include 
#include 
#include 
#include "system.h"

/* Act like "true" by default; false.c overrides this.  */
#ifndef EXIT_STATUS
# define EXIT_STATUS EXIT_SUCCESS
#endif

#if EXIT_STATUS == EXIT_SUCCESS
# define PROGRAM_NAME "true"
#else
# define PROGRAM_NAME "false"
#endif

#define AUTHORS "Jim Meyering"

/* The name this program was run with. */
char *program_name;

void
usage (int status)
{
  printf (_("\
Usage: %s [ignored command line arguments]\n\
  or:  %s OPTION\n\
"),
          program_name, program_name);
  printf ("%s\n\n",
          _(EXIT_STATUS == EXIT_SUCCESS
            ? "Exit with a status code indicating success."
            : "Exit with a status code indicating failure."));
  fputs (HELP_OPTION_DESCRIPTION, stdout);
  fputs (VERSION_OPTION_DESCRIPTION, stdout);
  printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
  printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
  exit (status);
}

int
main (int argc, char **argv)
{
  initialize_main (&argc, &argv);
  program_name = argv[0];
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  atexit (close_stdout);

  /* Recognize --help or --version only if it's the only command-line
     argument.  */
  if (argc == 2)
    {
      if (STREQ (argv[1], "--help"))
        usage (EXIT_STATUS);

      if (STREQ (argv[1], "--version"))
        version_etc (stdout, PROGRAM_NAME, GNU_PACKAGE, VERSION, AUTHORS,
                     (char *) NULL);
    }

  exit (EXIT_STATUS);
}

free-zombie's picture
Offline
Joined: 2006-03-08
the bloat is probably a

the bloat is probably a combination of the result of having true and false in one file and some GNU coding standards.

if (argc == 2) is an undocumented feature that shouldn't change the size signicantly.

tbuitenh's picture
Offline
Joined: 2005-12-21
Also, it uses locales (so

Also, it uses locales (so you should get a different help message if you set your system to a different language). This becomes a "necessity" because of having options at all...

free-zombie's picture
Offline
Joined: 2006-03-08
tbuitenh wrote: Also, it
tbuitenh wrote:

Also, it uses locales (so you should get a different help message if you set your system to a different language). This becomes a "necessity" because of having options at all...

looks like pure convention to me:

0:pts/4:~% LC_ALL=fr_FR date
mar jan  2 15:46:42 CET 2007
0:pts/4:~% LC_ALL=fr_FR /bin/true --help
Usage: /bin/true [ignored command line arguments]
  or:  /bin/true OPTION
Exit with a status code indicating success.

      --help     display this help and exit
      --version  output version information and exit

NOTE: your shell may have its own version of true, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

Report bugs to .
0:pts/4:~% 

The first line was to show that I have a french locale installed.

tbuitenh's picture
Offline
Joined: 2005-12-21
Then the locale thing

Then the locale thing definitely is bloat...

Offline
Joined: 2005-12-20
Heh many things from GNU

Heh many things from GNU are bloated. There was one time when I rewrote about 1/2 of the things from coreutils in both shell script (bourne, not bash) and C, the C versions were insanely small compared to GNU's. GNU's stuff has lots of crap that isn't even used, links with libraries not needed, and crazy things like that.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.