GNU Coreutils `time –version` and `/bin/true –version` work but `true –version` does not?

$ time --version
time (GNU Time) UNKNOWN
Copyright (C) 2018 Free Software Foundation, Inc.
...

$ /bin/true --version
true (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
...

$ true --version

$ echo 'nothing was printed on the previous line'

I’m using Ubuntu 22.04, GNU bash, version 5.1.16 (also tested with zsh 5.9).

Asked By: charmoniumQ

||

In Bash time is a keyword (see type time) and time is not interpreted as such. time makes Bash run an external executable which in your case is GNU time.

But true is a builtin (see type true). The fact you can use a backslash to suppress the time keyword (or any keyword, e.g. try if) probably misled you into thinking you can use a backslash to suppress a builtin. No, true still runs the builtin, not the GNU true. It’s quite evident with :; it runs the : builtin, not an external : executable which most likely does not exist in your OS (compare type -a : to type -a true; or try env :).

help true describes the builtin, it mentions no options.

How does true decide which behavior?

It seems the builtin ignores all command line arguments, no matter what they are. GNU true ignores all command line arguments, unless there is exactly one argument and the argument is --help or --version.

In Zsh the story is basically the same.

Answered By: Kamil Maciorowski
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.