About the "man test" command

Hello Friends

In Ubuntu if is executed the man test command appears the following:

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.

...

Observe the following part:

SYNOPSIS
       test EXPRESSION
       test
       [ EXPRESSION ]
       [ ]
       [ OPTION             <-----

Is [ OPTION an error? It should be [ OPTION ] right?

Just being curious

man test [ --help

is valid. So '[ option ’ means [ follow by option.

Now with equal opportunités and all that should it be renamed transexual test ?

Right … because test is an inbuilt shell command … it uses the shell syntax

Hello friends

Thanks for the replies

Howard

man test [ --help
is valid. So '[ option ’ means [ follow by option.

I confirmed it works. Interesting

Neville

Right … because test is an inbuilt shell command … it uses the shell syntax

In what kind of examples is used just only [?

About the if statement I’ve always seen

  • if ...; then
  • if [ ... ]; then
  • if [[ ... ]]; then

Wondered about this kind of syntax

In many (all?) unixes “test” is both an inbuilt and an external command.

Use test for the external command, [ . . . ] for the inbuilt shell command.

The man test and man [ commands appear to give the same output - in fact the two types of test are often hardlinks to the same binary.

" 6.4 Bash Conditional Expressions

Conditional expressions are used by the [[ compound command (see Conditional Constructs) and the test and [ builtin commands (see Bourne Shell Builtins). The test and [ commands determine their behavior based on the number of arguments; see the descriptions of those commands for any other command-specific actions."

I cant find any examples.

[ seems to be a synonym for test … ie you can use [ anywhere you can use the word test

I would have expected the man test command to display a hilarious test of one’s manliness. :smiley:

Things such as:

  1. Do you regurly get into barfights?
  2. Do you eat bricks for breakfast?
  3. Is your car a tank?

Etc.

IDK the fine points of it, but “[” is like an alias for “test”. It does not use the “]” for anything, not even parsing, AFAIK, but bash requires it or issues a syntax error.

Yes, it seems it is merely a shortcut.
The presentation in the man page needs a rewrite … it is confusing.

Joseph

IDK the fine points of it, but “[” is like an alias for “test”.

A very strange alias for a command

Neville

Yes, it seems it is merely a shortcut.

That should be documented

The presentation in the man page needs a rewrite … it is confusing

+1

One might ask why a man page for test exists … it is documented in the bash man page because it is part of bash.

eg. There is no man page for cd because cd is part of bash .

I correct myself …test is both a CLI command and a bash command.
How confusing is that?

it is documented in the bash man page because it is part of bash.

Interesting … I’ve confirmed the man bash command works … but exactly where is “test” included in the mentioned command?

Do you mean about

EXECIGNORE
              A colon-separated list of shell patterns (see Pattern Matching) defining the list of filenames to be ignored by command search us‐
              ing PATH.  Files whose full pathnames match one of these patterns are not considered executable files for the purposes of  comple‐
              tion and command execution via PATH lookup.  This does not affect the behavior of the [, test, and [[ commands.  Full pathnames in
              the  command  hash table are not subject to EXECIGNORE.  Use this variable to ignore shared library files that have the executable
              bit set, but are not executable files.  The pattern matching honors the setting of the extglob shell option.
       FCEDIT The default editor for the fc builtin command.

It about the This does not affect the behavior of the [, test, and [[ commands part?

Futhermore appears

 test and [ evaluate conditional expressions using a set of rules based on the number of arguments.
~ $ which cd
which: no cd in (/data/data/com.termux/files/usr/bin)
~ $ which test
/data/data/com.termux/files/usr/bin/test

Test is both a CLI command and a bash command, but cd is only a bash command.

See what I added to last reply

So the next question is … is the CLI test the same as the bash test?
and how does the shell know which one to use when you type ‘test’

As usual huge thanks for your support …

See what I added to last reply

Understood

I am going to read all the links provided in this link soon as I can

I must admit I do not fully understand this .
Maybe you can sort it out

According to this
https://www.baeldung.com/linux/one-line-if-else-condition#the--builtin
the [ has to have a trailing ]
I still dont understand?

It does not work for me

~ $
~ $ [ -s blank
bash: [: missing `]'
~ $ echo $?
2
~ $ [ -s blank ]
~ $ echo $?
0
~ $ test -s blank
~ $ echo $?
0
~ $

The file blank is present . Only the second and third cases work.
I dont understand [ option at all. … Is it a case of a poorly written man page?