summaryrefslogtreecommitdiff
path: root/static/unix-v10/man1/test.1
diff options
context:
space:
mode:
Diffstat (limited to 'static/unix-v10/man1/test.1')
-rw-r--r--static/unix-v10/man1/test.1206
1 files changed, 206 insertions, 0 deletions
diff --git a/static/unix-v10/man1/test.1 b/static/unix-v10/man1/test.1
new file mode 100644
index 00000000..e1b48d4a
--- /dev/null
+++ b/static/unix-v10/man1/test.1
@@ -0,0 +1,206 @@
+.TH TEST 1
+.CT 1 shell
+.SH NAME
+test, [, newer \- condition commands
+.SH SYNOPSIS
+.B test
+.I expr
+.PP
+\fB[\fR
+.I expr
+\fB]\fR
+.PP
+.B newer
+.I file1 file2
+.SH DESCRIPTION
+.I Test
+evaluates the expression
+.IR expr .
+If the value is true the exit status is 0; otherwise the
+exit status is nonzero.
+If there are no arguments the exit status is nonzero.
+.PP
+The following primitives are used to construct
+.IR expr .
+.TP \w'\fL-t\fI\ fildes\ 'u
+.BI -r " file"
+True if the file exists (is accessible) and is readable.
+.PD0
+.TP
+.BI -w " file"
+True if the file exists and is writable.
+.TP
+.BI -x " file"
+True if the file exists and has execute permission.
+.TP
+.BI -e " file
+True if the file exists.
+.TP
+.BI -f " file"
+True if the file exists and is a plain file.
+.TP
+.BI -d " file"
+True if the file exists and is a directory.
+.TP
+.BI -c " file"
+True if the file exists and is a character special file.
+.TP
+.BI -b " file"
+True if the file exists and is a block special file.
+.TP
+.BI -L " file"
+True if the file is a symbolic link.
+.TP
+.BI -u " file"
+True if the file exists and has set userid permission.
+.TP
+.BI -g " file"
+True if the file exists and has set groupid permission.
+.TP
+.BI -s " file"
+True if the file exists and has a size greater than zero.
+.TP
+.BI -t " fildes
+True if the open file whose file descriptor number is
+.I fildes
+(1 by default)
+is associated with a terminal device.
+.TP
+.B -S
+True if the effective userid is zero.
+.TP
+.IB s1 " = " s2
+True
+if the strings
+.I s1
+and
+.I s2
+are identical.
+.TP
+.IB s1 " != " s2
+True
+if the strings
+.I s1
+and
+.I s2
+are not identical.
+.TP
+s1
+True if
+.I s1
+is not the null string.
+(Deprecated.)
+.TP
+.BI -z " s1"
+True if the length of string
+.I s1
+is zero.
+.TP
+.IB n1 " -eq " n2
+True if the integers
+.I n1
+and
+.I n2
+are arithmetically equal.
+Any of the comparisons
+.BR -ne ,
+.BR -gt ,
+.BR -ge ,
+.BR -lt ,
+or
+.BR -le
+may be used in place of
+.BR -eq .
+The (nonstandard) construct
+.BI -l " string,
+meaning the length of
+.I string,
+may be used in place of an integer.
+.PD
+.PP
+These primaries may be combined with the
+following operators:
+.TP
+.B !
+unary negation operator
+.PD0
+.TP
+.B -o
+binary
+.I or
+operator
+.TP
+.B -a
+binary
+.I and
+operator; higher precedence than
+.BR -o
+.TP
+.BI "( " expr " )"
+parentheses for grouping.
+.PD
+.PP
+Notice that all the operators and flags are separate
+arguments to
+.IR test .
+Notice also that parentheses are meaningful
+to the Shell and must be escaped.
+.PP
+.B [
+is a synonym for
+.I test,
+except that
+.B [
+requires a closing
+.BR ] .
+.PP
+.I Newer
+returns a zero exit code if
+.I file1
+exists and
+.I file2
+does not, or if
+.I file1
+and
+.I file2
+both exist and
+.I file1
+was modified at least as recently
+as
+.IR file2 .
+It returns a non-zero return code otherwise.
+.SH EXAMPLES
+.I Test
+is a dubious way to check for specific character strings:
+it uses a process to do what a shell case statement can do.
+The first example is not only inefficient but wrong, because
+.I test
+understands the purported string
+.B \&"-c"
+as an option.
+Furthermore
+.B $1
+might be empty.
+.IP
+.EX
+if test $1 = "-c" # wrong!
+then echo OK
+fi
+.EE
+.LP
+A correct way is
+.IP
+.EX
+case "$1" in
+-c) echo OK
+esac
+.EE
+.PP
+Test whether
+.L abc
+is in the current directory.
+.IP
+.B test -e abc -o -L abc
+.SH "SEE ALSO"
+.IR sh (1),
+.IR find (1)