xref: /freebsd/bin/test/test.1 (revision e5bf7bf46c7f6f808f7dab9999edbacfa3500490)
14b88c807SRodney W. Grimes.\" Copyright (c) 1991, 1993
24b88c807SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
34b88c807SRodney W. Grimes.\"
44b88c807SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
54b88c807SRodney W. Grimes.\" the Institute of Electrical and Electronics Engineers, Inc.
64b88c807SRodney W. Grimes.\"
74b88c807SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
84b88c807SRodney W. Grimes.\" modification, are permitted provided that the following conditions
94b88c807SRodney W. Grimes.\" are met:
104b88c807SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
114b88c807SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
124b88c807SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
134b88c807SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
144b88c807SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
154b88c807SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
164b88c807SRodney W. Grimes.\"    must display the following acknowledgement:
174b88c807SRodney W. Grimes.\"	This product includes software developed by the University of
184b88c807SRodney W. Grimes.\"	California, Berkeley and its contributors.
194b88c807SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
204b88c807SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
214b88c807SRodney W. Grimes.\"    without specific prior written permission.
224b88c807SRodney W. Grimes.\"
234b88c807SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
244b88c807SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
254b88c807SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
264b88c807SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
274b88c807SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
284b88c807SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
294b88c807SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
304b88c807SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
314b88c807SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
324b88c807SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
334b88c807SRodney W. Grimes.\" SUCH DAMAGE.
344b88c807SRodney W. Grimes.\"
354b88c807SRodney W. Grimes.\"     @(#)test.1	8.1 (Berkeley) 5/31/93
36e5bf7bf4SJoseph Koshy.\"	$Id: test.1,v 1.7 1998/09/07 16:59:05 cracauer Exp $
374b88c807SRodney W. Grimes.\"
384b88c807SRodney W. Grimes.Dd May 31, 1993
394b88c807SRodney W. Grimes.Dt TEST 1
404b88c807SRodney W. Grimes.Os
414b88c807SRodney W. Grimes.Sh NAME
424b88c807SRodney W. Grimes.Nm test
434b88c807SRodney W. Grimes.Nd condition evaluation utility
444b88c807SRodney W. Grimes.Sh SYNOPSIS
454b88c807SRodney W. Grimes.Nm test
464b88c807SRodney W. Grimes.Ar expression
474b88c807SRodney W. Grimes.Sh DESCRIPTION
484b88c807SRodney W. GrimesThe
499ba8bd65SPhilippe Charnier.Nm
504b88c807SRodney W. Grimesutility evaluates the expression and, if it evaluates
514b88c807SRodney W. Grimesto true, returns a zero (true) exit status; otherwise
524b88c807SRodney W. Grimesit returns 1 (false).
534b88c807SRodney W. GrimesIf there is no expression, test also
544b88c807SRodney W. Grimesreturns 1 (false).
554b88c807SRodney W. Grimes.Pp
564b88c807SRodney W. GrimesAll operators and flags are separate arguments to the
579ba8bd65SPhilippe Charnier.Nm
584b88c807SRodney W. Grimesutility.
594b88c807SRodney W. Grimes.Pp
604b88c807SRodney W. GrimesThe following primaries are used to construct expression:
619ba8bd65SPhilippe Charnier.Bl -tag -width indent
624b88c807SRodney W. Grimes.It Fl b Ar file
634b88c807SRodney W. GrimesTrue if
644b88c807SRodney W. Grimes.Ar file
654b88c807SRodney W. Grimesexists and is a block special
664b88c807SRodney W. Grimesfile.
674b88c807SRodney W. Grimes.It Fl c Ar file
684b88c807SRodney W. GrimesTrue if
694b88c807SRodney W. Grimes.Ar file
704b88c807SRodney W. Grimesexists and is a character
714b88c807SRodney W. Grimesspecial file.
724b88c807SRodney W. Grimes.It Fl d Ar file
734b88c807SRodney W. GrimesTrue if
744b88c807SRodney W. Grimes.Ar file
754b88c807SRodney W. Grimesexists and is a directory.
764b88c807SRodney W. Grimes.It Fl e Ar file
774b88c807SRodney W. GrimesTrue if
784b88c807SRodney W. Grimes.Ar file
794b88c807SRodney W. Grimesexists (regardless of type).
804b88c807SRodney W. Grimes.It Fl f Ar file
814b88c807SRodney W. GrimesTrue if
824b88c807SRodney W. Grimes.Ar file
834b88c807SRodney W. Grimesexists and is a regular file.
844b88c807SRodney W. Grimes.It Fl g Ar file
854b88c807SRodney W. GrimesTrue if
864b88c807SRodney W. Grimes.Ar file
874b88c807SRodney W. Grimesexists and its set group ID flag
884b88c807SRodney W. Grimesis set.
894b88c807SRodney W. Grimes.It Fl h Ar file
904b88c807SRodney W. GrimesTrue if
914b88c807SRodney W. Grimes.Ar file
924b88c807SRodney W. Grimesexists and is a symbolic link.
934b88c807SRodney W. Grimes.It Fl n Ar string
944b88c807SRodney W. GrimesTrue if the length of
954b88c807SRodney W. Grimes.Ar string
964b88c807SRodney W. Grimesis nonzero.
974b88c807SRodney W. Grimes.It Fl p Ar file
984b88c807SRodney W. GrimesTrue if
994b88c807SRodney W. Grimes.Ar file
1004b88c807SRodney W. Grimesis a named pipe
1014b88c807SRodney W. Grimes.Po Tn FIFO Pc .
10223f8fb3dSMartin Cracauer.It Fl S Ar file
10323f8fb3dSMartin CracauerTrue if
10423f8fb3dSMartin Cracauer.Ar file
10523f8fb3dSMartin Cracaueris a socket.
1064b88c807SRodney W. Grimes.It Fl r Ar file
1074b88c807SRodney W. GrimesTrue if
108c263cc21SPhilippe Charnier.Ar file
109c263cc21SPhilippe Charnierexists and is readable.
1104b88c807SRodney W. Grimes.It Fl s Ar file
1114b88c807SRodney W. GrimesTrue if
1124b88c807SRodney W. Grimes.Ar file
1134b88c807SRodney W. Grimesexists and has a size greater
1144b88c807SRodney W. Grimesthan zero.
1154b88c807SRodney W. Grimes.It Fl t Ar [file_descriptor]
1164b88c807SRodney W. GrimesTrue if the file whose file descriptor number
1174b88c807SRodney W. Grimesis
1184b88c807SRodney W. Grimes.Ar file_descriptor
1194b88c807SRodney W. Grimes(default 1) is open and is
1204b88c807SRodney W. Grimesassociated with a terminal.
1214b88c807SRodney W. Grimes.It Fl u Ar file
1224b88c807SRodney W. GrimesTrue if
1234b88c807SRodney W. Grimes.Ar file
1244b88c807SRodney W. Grimesexists and its set user ID flag
1254b88c807SRodney W. Grimesis set.
1264b88c807SRodney W. Grimes.It Fl w Ar file
1274b88c807SRodney W. GrimesTrue if
1284b88c807SRodney W. Grimes.Ar file
1294b88c807SRodney W. Grimesexists and is writable.
1304b88c807SRodney W. GrimesTrue
1314b88c807SRodney W. Grimesindicates only that the write flag is on.
1324b88c807SRodney W. GrimesThe file is not writable on a read-only file
1334b88c807SRodney W. Grimessystem even if this test indicates true.
1344b88c807SRodney W. Grimes.It Fl x Ar file
1354b88c807SRodney W. GrimesTrue if
1364b88c807SRodney W. Grimes.Ar file
1374b88c807SRodney W. Grimesexists and is executable.
1384b88c807SRodney W. GrimesTrue
1394b88c807SRodney W. Grimesindicates only that the execute flag is on.
1404b88c807SRodney W. GrimesIf
1414b88c807SRodney W. Grimes.Ar file
1424b88c807SRodney W. Grimesis a directory, true indicates that
1434b88c807SRodney W. Grimes.Ar file
1444b88c807SRodney W. Grimescan be searched.
1454b88c807SRodney W. Grimes.It Fl z Ar string
1464b88c807SRodney W. GrimesTrue if the length of
1474b88c807SRodney W. Grimes.Ar string
1484b88c807SRodney W. Grimesis zero.
1494b88c807SRodney W. Grimes.It Ar string
1504b88c807SRodney W. GrimesTrue if
1514b88c807SRodney W. Grimes.Ar string
1524b88c807SRodney W. Grimesis not the null
1534b88c807SRodney W. Grimesstring.
1544b88c807SRodney W. Grimes.It Ar \&s\&1 Cm \&= Ar \&s\&2
1554b88c807SRodney W. GrimesTrue if the strings
1564b88c807SRodney W. Grimes.Ar \&s\&1
1574b88c807SRodney W. Grimesand
1584b88c807SRodney W. Grimes.Ar \&s\&2
1594b88c807SRodney W. Grimesare identical.
1604b88c807SRodney W. Grimes.It Ar \&s\&1 Cm \&!= Ar \&s\&2
1614b88c807SRodney W. GrimesTrue if the strings
1624b88c807SRodney W. Grimes.Ar \&s\&1
1634b88c807SRodney W. Grimesand
1644b88c807SRodney W. Grimes.Ar \&s\&2
1654b88c807SRodney W. Grimesare not identical.
1664b88c807SRodney W. Grimes.It Ar \&n\&1 Fl \&eq Ar \&n\&2
1674b88c807SRodney W. GrimesTrue if the integers
1684b88c807SRodney W. Grimes.Ar \&n\&1
1694b88c807SRodney W. Grimesand
1704b88c807SRodney W. Grimes.Ar \&n\&2
1714b88c807SRodney W. Grimesare algebraically
1724b88c807SRodney W. Grimesequal.
1734b88c807SRodney W. Grimes.It Ar \&n\&1 Fl \&ne Ar \&n\&2
1744b88c807SRodney W. GrimesTrue if the integers
1754b88c807SRodney W. Grimes.Ar \&n\&1
1764b88c807SRodney W. Grimesand
1774b88c807SRodney W. Grimes.Ar \&n\&2
1784b88c807SRodney W. Grimesare not
1794b88c807SRodney W. Grimesalgebraically equal.
1804b88c807SRodney W. Grimes.It Ar \&n\&1 Fl \&gt Ar \&n\&2
1814b88c807SRodney W. GrimesTrue if the integer
1824b88c807SRodney W. Grimes.Ar \&n\&1
1834b88c807SRodney W. Grimesis algebraically
1844b88c807SRodney W. Grimesgreater than the integer
1854b88c807SRodney W. Grimes.Ar \&n\&2 .
1864b88c807SRodney W. Grimes.It Ar \&n\&1 Fl \&ge Ar \&n\&2
1874b88c807SRodney W. GrimesTrue if the integer
1884b88c807SRodney W. Grimes.Ar \&n\&1
1894b88c807SRodney W. Grimesis algebraically
1904b88c807SRodney W. Grimesgreater than or equal to the integer
1914b88c807SRodney W. Grimes.Ar \&n\&2 .
1924b88c807SRodney W. Grimes.It Ar \&n\&1 Fl \&lt Ar \&n\&2
1934b88c807SRodney W. GrimesTrue if the integer
1944b88c807SRodney W. Grimes.Ar \&n\&1
1954b88c807SRodney W. Grimesis algebraically less
1964b88c807SRodney W. Grimesthan the integer
1974b88c807SRodney W. Grimes.Ar \&n\&2 .
1984b88c807SRodney W. Grimes.It Ar \&n\&1 Fl \&le Ar \&n\&2
1994b88c807SRodney W. GrimesTrue if the integer
2004b88c807SRodney W. Grimes.Ar \&n\&1
2014b88c807SRodney W. Grimesis algebraically less
2024b88c807SRodney W. Grimesthan or equal to the integer
2034b88c807SRodney W. Grimes.Ar \&n\&2 .
2044b88c807SRodney W. Grimes.El
2054b88c807SRodney W. Grimes.Pp
2064b88c807SRodney W. GrimesThese primaries can be combined with the following operators:
2074b88c807SRodney W. Grimes.Bl -tag -width Ar
2084b88c807SRodney W. Grimes.It Cm \&! Ar expression
2094b88c807SRodney W. GrimesTrue if
2104b88c807SRodney W. Grimes.Ar expression
2114b88c807SRodney W. Grimesis false.
2124b88c807SRodney W. Grimes.It Ar expression1 Fl a Ar expression2
2134b88c807SRodney W. GrimesTrue if both
2144b88c807SRodney W. Grimes.Ar expression1
2154b88c807SRodney W. Grimesand
2164b88c807SRodney W. Grimes.Ar expression2
2174b88c807SRodney W. Grimesare true.
2184b88c807SRodney W. Grimes.It Ar expression1 Fl o Ar expression2
2194b88c807SRodney W. GrimesTrue if either
2204b88c807SRodney W. Grimes.Ar expression1
2214b88c807SRodney W. Grimesor
2224b88c807SRodney W. Grimes.Ar expression2
2234b88c807SRodney W. Grimesare true.
2244b88c807SRodney W. Grimes.It Cm \&( Ns Ar expression Ns Cm \&)
2254b88c807SRodney W. GrimesTrue if expression is true.
2264b88c807SRodney W. Grimes.El
2274b88c807SRodney W. Grimes.Pp
2284b88c807SRodney W. GrimesThe
2294b88c807SRodney W. Grimes.Fl a
2304b88c807SRodney W. Grimesoperator has higher precedence than the
2314b88c807SRodney W. Grimes.Fl o
2324b88c807SRodney W. Grimesoperator.
2334b88c807SRodney W. Grimes.Sh GRAMMAR AMBIGUITY
2344b88c807SRodney W. GrimesThe
2359ba8bd65SPhilippe Charnier.Nm
2364b88c807SRodney W. Grimesgrammar is inherently ambiguous.  In order to assure a degree of consistency,
2374b88c807SRodney W. Grimesthe cases described in the
2384b88c807SRodney W. Grimes.St -p1003.2 ,
2394b88c807SRodney W. Grimessection D11.2/4.62.4, standard
2404b88c807SRodney W. Grimesare evaluated consistently according to the rules specified in the
2414b88c807SRodney W. Grimesstandards document.  All other cases are subject to the ambiguity in the
2424b88c807SRodney W. Grimescommand semantics.
2434b88c807SRodney W. Grimes.Sh RETURN VALUES
2444b88c807SRodney W. GrimesThe
2459ba8bd65SPhilippe Charnier.Nm
2464b88c807SRodney W. Grimesutility exits with one of the following values:
2474b88c807SRodney W. Grimes.Bl -tag -width Ds
2484b88c807SRodney W. Grimes.It 0
2494b88c807SRodney W. Grimesexpression evaluated to true.
2504b88c807SRodney W. Grimes.It 1
2514b88c807SRodney W. Grimesexpression evaluated to false or expression was
2524b88c807SRodney W. Grimesmissing.
2534b88c807SRodney W. Grimes.It >1
2544b88c807SRodney W. GrimesAn error occurred.
2554b88c807SRodney W. Grimes.El
256e5bf7bf4SJoseph Koshy.Sh SEE ALSO
257e5bf7bf4SJoseph Koshy.Xr expr 1 ,
258e5bf7bf4SJoseph Koshy.Xr sh 1
2594b88c807SRodney W. Grimes.Sh STANDARDS
2604b88c807SRodney W. GrimesThe
2619ba8bd65SPhilippe Charnier.Nm
2624b88c807SRodney W. Grimesfunction is expected to be
2634b88c807SRodney W. Grimes.St -p1003.2
2644b88c807SRodney W. Grimescompatible.
265