|
|
coherent
test Command test
Evaluate conditional expression
tteesstt _e_x_p_r_e_s_s_i_o_n ...
tteesstt evaluates an _e_x_p_r_e_s_s_i_o_n, which consists of string
comparisons, numerical comparisons, and tests of file attributes.
For example, a tteesstt command might be used within a shell command
file to test whether a certain file exists and is readable. The
logical result (true or false) of the _e_x_p_r_e_s_s_i_o_n is returned by
the command, for use by a shell construct such as iiff.
_e_x_p_r_e_s_s_i_o_n is constructed from the following elements, which are
true if the given condition holds and false if not:
_e_x_p_1 -aa _e_x_p_2
Both expressions _e_x_p_1 and _e_x_p_2 are true.
-bb _f_i_l_e _f_i_l_e is a block-special device. kksshh only.
-cc _f_i_l_e _f_i_l_e is a character-special file. kksshh only.
-dd _f_i_l_e _f_i_l_e exists and is a directory.
_f_i_l_e_1 -eeff _f_i_l_e_2
_f_i_l_e_1 is the same file as _f_i_l_e_2. kksshh only.
_n_1 -eeqq _n_2 Numbers _n_1 and _n_2 are equal.
-ff _f_i_l_e _f_i_l_e exists and is not a directory.
-gg _f_i_l_e File mode has sseettggiidd bit. kksshh only.
_n_1 -ggee _n_2 Number _n_1 is greater than or equal to _n_2.
_n_1 -ggtt _n_2 Number _n_1 is greater than _n_2.
-kk _f_i_l_e File mode has sticky bit. kksshh only.
-LL _f_i_l_e File is a symbolic link. kksshh only.
_n_1 -llee _n_2 Number _n_1 is less than or equal to _n_2.
_n_1 -lltt _n_2 Number _n_1 is less than _n_2.
-nn _s_t_r_i_n_g _s_t_r_i_n_g has nonzero length.
_n_1 -nnee _n_2 Numbers _n_1 and _n_2 are not equal.
_f_i_l_e_1 -nntt _f_i_l_e_2
_f_i_l_e_1 is newer than kksshh only.
_e_x_p_1 -oo _e_x_p_2
Either expression _e_x_p_1 or _e_x_p_2 is true. -aa has greater
precedence than -oo.
COHERENT Lexicon Page 1
test Command test
_f_i_l_e_1 -oott _f_i_l_e_2
_f_i_l_e_1 is older than _f_i_l_e_2. kksshh only.
-pp _f_i_l_e _f_i_l_e is a named pipe. kksshh only.
-rr _f_i_l_e _f_i_l_e exists and is readable.
-ss _f_i_l_e _f_i_l_e exists and has nonzero size.
-tt [_f_d] _f_d is the file descriptor number of a file which is
open and a terminal. If no _f_d is given, it defaults to
the standard output (file descriptor 1).
-uu _f_i_l_e File mode has sseettuuiidd set. kksshh only.
-ww _f_i_l_e _f_i_l_e exists and is writable.
-xx _f_i_l_e _f_i_l_e exists and executable. kksshh only.
-zz _s_t_r_i_n_g _s_t_r_i_n_g has zero length (is a null string).
_s_t_r_i_n_g _s_t_r_i_n_g has nonzero length.
_s_t_r_i_n_g_1 = _s_t_r_i_n_g_2
_s_t_r_i_n_g_1 is equal to _s_t_r_i_n_g_2.
! _e_x_p Negates the logical value of expression _e_x_p.
_s_t_r_i_n_g_1 != _s_t_r_i_n_g_2
_s_t_r_i_n_g_1 is not equal to _s_t_r_i_n_g_2.
(_e_x_p) Parentheses allow expression grouping.
***** Example *****
The following example uses the tteesstt command to determine whether
a file is writable.
if test ! -w /dev/lp
then
echo The line printer is inaccessible.
fi
Under COHERENT, the command `[' is linked to tteesstt. If invoked as
`[', tteesstt checks that its last argument is `]'. This allows an
alternative syntax: simply enclose _e_x_p_r_e_s_s_i_o_n in square brackets.
For example, the above example can be written as follows:
COHERENT Lexicon Page 2
test Command test
if [ ! -w /dev/lp ]
then
echo The line printer is inaccessible.
fi
For a more extended example of the square-bracket syntax, see sshh.
***** See Also *****
ccoommmmaannddss, eexxpprr, ffiinndd, iiff, kksshh, sshh, wwhhiillee
***** Notes *****
The Korn shell's version of this command is based on the public-
domain version written by Erik Baalbergen and Arnold Robbins.
COHERENT Lexicon Page 3
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.