ELTEST(1)

NAME
eltest - evaluate an expression and indicate the result via its exit status

SYNOPSIS
eltest expression...

DESCRIPTION
eltest acts as the generic POSIX test utility[1], but it diverges from the specification on how it parses ambiguous arguments: see below.

eltest supports all the standard test operands, plus all the extensions from GNU test[2], plus a few extensions from the ‘test’ builtin from bash[3]. The extensions to POSIX test are listed below.

eltest accepts an arbitrary number of arguments and, if the expression is valid, always returns the result of the expression no matter how complex it is.

  Extensions

expr1 -a expr2
    Test whether expr1 and expr2 are true. If expr1 is false, then expr2 is not evaluated.

expr1 -o expr2
    Test whether expr1 or expr2 is true. If expr1 is true, then expr2 is not evaluated.

-k file
    Test whether file has the sticky bit.

-O file
    Test whether file is owned by the effective uid of the current process.

-U file
    As for ‘-O’.

-G file
    Test whether file' s gid is the effective gid of the current process.

-N file
    Test whether file exists and has been modified since it was last read.

file1 -nt file2
    Test whether file1 has a (strictly) newer modification date than file2.

file1 -ot file2
    Test whether file1 has a (strictly) older modification date than file2.

file1 -ef file2
    Test whether file1 and file2 are physically the same file (same device and inode numbers).

-v var
    Test whether the var variable is defined in the current environment.

string =~ pattern
    Tries to match string against extended regular expression pattern. True if any part of string matches pattern; in order to match whole strings, you must anchor pattern with ‘^’ and ‘$’ markers.

  Argument disambiguation
Unlike test [1], which has different fixed syntax trees depending on the number of arguments it receives and has undefined behaviour when called with more than 5 arguments, eltest accepts any number of arguments and builds its syntax trees on the fly. This means that expressions such as ‘-n = -n’ cannot be automatically disambiguated: eltest does not know that there are 3 arguments, so when it reads the first ‘-n’ it assumes that it is an unary operator, then when it reads ‘=’ it assumes it is the argument to ‘-n’, then when it reads the second ‘-n’ it exits with a syntax error.

Doing otherwise would result in a combinatory explosion of possible syntax trees, making it easy for users to trigger unbounded RAM consumption, and turning a simple utility into a programming nightmare. This is why POSIX test [1] is so restricted. But we don't want the same restrictions.

So, instead, eltest provides the user with a mechanism to make sure that operands are never mistaken for operators:

•   A word that looks like an operator will always be interpreted like an operator. So, expressions like ‘-n = -n’ will result in a syntax error, because the first ‘-n’ will never be understood as data for the ‘=’ operator.

•   A word that starts with a ‘\’ (backslash) will always be interpreted like data, never like an operator, and the backslash will be removed. This means ‘\-n = \-n’ is a valid expression testing the equality between the strings ‘-n’ and ‘-n’.

    •   Be aware that execline as well as the shell use one backlash for their own unquoting mechanism, so when using backslashes in an execline or shell script, they must be doubled. You would probably need to type something like ‘\\-n = \\-n’.

•   So, if your script tests equality between ‘$a’ and ‘$b’, and there's a possiblity that the contents of these variables look like eltest operators, the proper syntax would be: ‘eltest \\${a} = \\${b}’.

Note that these details are irrelevant to a huge majority of eltest use cases, because most of the time users only need a simple test such as ‘eltest -r ${file}’ to check that ‘$file’ is readable, and there's no possible ambiguity. So don't panic over this.

  Notes
eltest is a replacement for the ill-named, and now deprecated, s6-test(1) program, part of the (just as ill-named) s6-portable-utils[4] package. It is too valuable a utility to be part of a marginal package, and has nothing to do with s6[5].

OPTIONS
None.

EXIT STATUS

0   The test is true.

1   The test is false.

100 Wrong usage.

101 Internal error (should never happen, warrants a bug-report).

111 System call failure.

SEE ALSO
[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html

[2] https://man7.org/linux/man-pages/man1/test.1.html

[3] https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-Conditional-Expressions

[4] https://skarnet.org/software/s6-portable-utils/

[5] https://skarnet.org/software/s6/

This man page is ported from the authoritative documentation at: https://skarnet.org/software/execline/eltest.html

STANDARDS
eltest is not suitable as a Single Unix test [1] program, due to the way it disambiguates between arguments and operators, as described in the Argument diambiguation section. However, if you never use arguments that start with a backslash, or that have the same name as an existing operator, then eltest exhibits the same behaviour as test.

AUTHORS
Laurent Bercot Alexis <flexibeast@gmail.com> (man page port)