Bash Primary – Definition of a Primary in Bash

bash

From Bash's manual

6.4 Bash Conditional Expressions

Conditional expressions are used by the [[ compound command and the
test and [ builtin commands.

Expressions may be unary or binary. Unary
expressions are often used to examine the status of a file. There are
string operators and numeric comparison operators as well. If the file
argument to one of the primaries is of the form /dev/fd/N, then file
descriptor N is checked. If the file argument to one of the primaries
is one of /dev/stdin, /dev/stdout, or /dev/stderr, file descriptor 0,
1, or 2, respectively, is checked.

When used with [[, the ‘<’ and ‘>’
operators sort lexicographically using the current locale. The test
command uses ASCII ordering.

Unless otherwise specified, primaries
that operate on files follow symbolic links and operate on the target
of the link, rather than the link itself.

What is the definition of a primary?

What is the difference between a primary and an operator or operation?

Best Answer

As noted, this is jargon. The bash reference manual does not define the term; it is assumed that the reader knows about it.

You can easily find it used for operands in an arithmetic expression. See for example Arithmetic Expressions in a Fortran 77 Language Reference Manual, which says

A primary is the basic component in an arithmetic expression. The forms of a primary are the following:

  • an unsigned arithmetic constant

  • a symbolic name of an arithmetic constant

  • an arithmetic variable reference

  • an arithmetic array element reference

  • an arithmetic function reference

  • an arithmetic expression enclosed in parentheses

In POSIX, it is (still) used mostly relying upon the reader's prior knowledge of the term. For instance, in the shell command language, it refers to primaries of the find command:

(such as in the argument to the find - name primary when find is being called using one of the exec functions as defined in the System Interfaces volume of POSIX.1-2008, or in the pattern argument to the fnmatch() function),

and on reading that section it is apparent that primaries means the same as operands. That is, at each level of command-parsing, the command (or primary) has some further primaries to consider until all that are left are constants or variables: aka "operand".