Score:2

Why is test --help not working?

in flag

My Ubuntu is working good.

$ lsb_release -a
LSB Version:    core-11.1.0ubuntu4-noarch:printing-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:    22.04
Codename:   jammy

When I try built-in bash test command :

test --version
test --help

I see no output.

What works :

  • man test gives a man page ( GNU coreutils 8.32 )
  • info test|more
  • test -1 -gt -2 && echo yes

It shows

TEST(1)                          User Commands                         TEST(1)

NAME
       test - check file types and compare values

SYNOPSIS
       test EXPRESSION
       test
       [ EXPRESSION ]
       [ ]
       [ OPTION

DESCRIPTION
       Exit with the status determined by EXPRESSION.

       --help display this help and exit

       --version

that

test --version

should work.

Where is the problem?

hr flag
If you want to see documentation for the bash builtin `test`, use `help test` or `man bash`
Score:4
hr flag

Your question asks about "built-in bash test command" but the man and info pages you are quoting are those for the external /usr/bin/test command provided by the coreutils package.

The --help and --version options only apply if you explicitly invoke the non-builtin test program, and only when you invoke it as [ not test, as documented in the info extract:

If EXPRESSION is omitted, ‘test’ returns false. If EXPRESSION is a single argument, ‘test’ returns false if the argument is null and true otherwise. The argument can be any string, including strings like ‘-d’, ‘-1’, ‘--’, ‘--help’, and ‘--version’ that most other programs would treat as options. To get help and version information, invoke the commands ‘[ --help’ and ‘[ --version’, without the usual closing brackets.

Ex.

$ /usr/bin/[ --version
[ (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Kevin Braunsdorf and Matthew Bradburn.
in flag
which test gives /usr/bin/test
hr flag
@Adam the `which` command ignores shell builtins - in `bash`, use `type test` (or `type -a test` for an ordered list) instead. See for example [Why not use "which"? What to use then?](https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then)
in flag
How can explicitly invoke the builtin test program?
hr flag
@Adam if you just type `test` in the bash shell, you will get the builtin version (provided you haven't overridden `test` with an alias or shell function of your own). The `COMMAND EXECUTION` section of `man bash` explains more fully.
terdon avatar
cn flag
@Adam also, the builtin tool has no `--help` option. To see the help/manual of a builtin, you run `help` and the builtin's name. In your case, you want `help test`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.