xref: /minix3/bin/test/test.1 (revision 93184c84570653a2ed30858e700fd7e667703905)
1*93184c84SSevan Janiyan.\"	$NetBSD: test.1,v 1.30 2016/08/12 03:17:41 sevan Exp $
23a19ae75SLionel Sambuc.\"
33a19ae75SLionel Sambuc.\" Copyright (c) 1991, 1993
43a19ae75SLionel Sambuc.\"	The Regents of the University of California.  All rights reserved.
53a19ae75SLionel Sambuc.\"
63a19ae75SLionel Sambuc.\" This code is derived from software contributed to Berkeley by
73a19ae75SLionel Sambuc.\" the Institute of Electrical and Electronics Engineers, Inc.
83a19ae75SLionel Sambuc.\"
93a19ae75SLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
103a19ae75SLionel Sambuc.\" modification, are permitted provided that the following conditions
113a19ae75SLionel Sambuc.\" are met:
123a19ae75SLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
133a19ae75SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
143a19ae75SLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
153a19ae75SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
163a19ae75SLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
173a19ae75SLionel Sambuc.\" 3. Neither the name of the University nor the names of its contributors
183a19ae75SLionel Sambuc.\"    may be used to endorse or promote products derived from this software
193a19ae75SLionel Sambuc.\"    without specific prior written permission.
203a19ae75SLionel Sambuc.\"
213a19ae75SLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
223a19ae75SLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
233a19ae75SLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
243a19ae75SLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
253a19ae75SLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
263a19ae75SLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
273a19ae75SLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
283a19ae75SLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
293a19ae75SLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
303a19ae75SLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313a19ae75SLionel Sambuc.\" SUCH DAMAGE.
323a19ae75SLionel Sambuc.\"
333a19ae75SLionel Sambuc.\"     @(#)test.1	8.1 (Berkeley) 5/31/93
343a19ae75SLionel Sambuc.\"
35*93184c84SSevan Janiyan.Dd August 12, 2016
363a19ae75SLionel Sambuc.Dt TEST 1
373a19ae75SLionel Sambuc.Os
383a19ae75SLionel Sambuc.Sh NAME
393a19ae75SLionel Sambuc.Nm test ,
403a19ae75SLionel Sambuc.Nm \&[
413a19ae75SLionel Sambuc.Nd condition evaluation utility
423a19ae75SLionel Sambuc.Sh SYNOPSIS
4384d9c625SLionel Sambuc.Nm
443a19ae75SLionel Sambuc.Ar expression
453a19ae75SLionel Sambuc.Nm \&[
463a19ae75SLionel Sambuc.Ar expression Cm \&]
473a19ae75SLionel Sambuc.Sh DESCRIPTION
483a19ae75SLionel SambucThe
4984d9c625SLionel Sambuc.Nm
503a19ae75SLionel Sambucutility evaluates
513a19ae75SLionel Sambuc.Ar expression
523a19ae75SLionel Sambucand, if it evaluates
533a19ae75SLionel Sambucto true, returns a zero (true) exit status; otherwise
543a19ae75SLionel Sambucit returns 1 (false).
553a19ae75SLionel SambucIf
563a19ae75SLionel Sambuc.Ar expression
573a19ae75SLionel Sambucis not given,
5884d9c625SLionel Sambuc.Nm
593a19ae75SLionel Sambucalso
603a19ae75SLionel Sambucreturns 1 (false).
613a19ae75SLionel Sambuc.Pp
623a19ae75SLionel SambucAll operators and flags are separate arguments to the
6384d9c625SLionel Sambuc.Nm
643a19ae75SLionel Sambucutility.
653a19ae75SLionel Sambuc.Pp
663a19ae75SLionel SambucThe following primaries are used to construct
673a19ae75SLionel Sambuc.Ar expression :
683a19ae75SLionel Sambuc.Bl -tag -width Ar
693a19ae75SLionel Sambuc.It Fl b Ar file
703a19ae75SLionel SambucTrue if
713a19ae75SLionel Sambuc.Ar file
723a19ae75SLionel Sambucexists and is a block special
733a19ae75SLionel Sambucfile.
743a19ae75SLionel Sambuc.It Fl c Ar file
753a19ae75SLionel SambucTrue if
763a19ae75SLionel Sambuc.Ar file
773a19ae75SLionel Sambucexists and is a character
783a19ae75SLionel Sambucspecial file.
793a19ae75SLionel Sambuc.It Fl d Ar file
803a19ae75SLionel SambucTrue if
813a19ae75SLionel Sambuc.Ar file
823a19ae75SLionel Sambucexists and is a directory.
833a19ae75SLionel Sambuc.It Fl e Ar file
843a19ae75SLionel SambucTrue if
853a19ae75SLionel Sambuc.Ar file
863a19ae75SLionel Sambucexists (regardless of type).
873a19ae75SLionel Sambuc.It Fl f Ar file
883a19ae75SLionel SambucTrue if
893a19ae75SLionel Sambuc.Ar file
903a19ae75SLionel Sambucexists and is a regular file.
913a19ae75SLionel Sambuc.It Fl g Ar file
923a19ae75SLionel SambucTrue if
933a19ae75SLionel Sambuc.Ar file
943a19ae75SLionel Sambucexists and its set group ID flag
953a19ae75SLionel Sambucis set.
963a19ae75SLionel Sambuc.It Fl h Ar file
973a19ae75SLionel SambucTrue if
983a19ae75SLionel Sambuc.Ar file
993a19ae75SLionel Sambucexists and is a symbolic link.
1003a19ae75SLionel Sambuc.It Fl k Ar file
1013a19ae75SLionel SambucTrue if
1023a19ae75SLionel Sambuc.Ar file
1033a19ae75SLionel Sambucexists and its sticky bit is set.
1043a19ae75SLionel Sambuc.It Fl n Ar string
1053a19ae75SLionel SambucTrue if the length of
1063a19ae75SLionel Sambuc.Ar string
1073a19ae75SLionel Sambucis nonzero.
1083a19ae75SLionel Sambuc.It Fl p Ar file
1093a19ae75SLionel SambucTrue if
1103a19ae75SLionel Sambuc.Ar file
1113a19ae75SLionel Sambucexists and is a named pipe
1123a19ae75SLionel Sambuc.Po Tn FIFO Pc .
1133a19ae75SLionel Sambuc.It Fl r Ar file
1143a19ae75SLionel SambucTrue if
1153a19ae75SLionel Sambuc.Ar file
1163a19ae75SLionel Sambucexists and is readable.
1173a19ae75SLionel Sambuc.It Fl s Ar file
1183a19ae75SLionel SambucTrue if
1193a19ae75SLionel Sambuc.Ar file
1203a19ae75SLionel Sambucexists and has a size greater
1213a19ae75SLionel Sambucthan zero.
1223a19ae75SLionel Sambuc.It Fl t Ar file_descriptor
1233a19ae75SLionel SambucTrue if the file whose file descriptor number
1243a19ae75SLionel Sambucis
1253a19ae75SLionel Sambuc.Ar file_descriptor
1263a19ae75SLionel Sambucis open and is associated with a terminal.
1273a19ae75SLionel Sambuc.It Fl u Ar file
1283a19ae75SLionel SambucTrue if
1293a19ae75SLionel Sambuc.Ar file
1303a19ae75SLionel Sambucexists and its set user ID flag
1313a19ae75SLionel Sambucis set.
1323a19ae75SLionel Sambuc.It Fl w Ar file
1333a19ae75SLionel SambucTrue if
1343a19ae75SLionel Sambuc.Ar file
1353a19ae75SLionel Sambucexists and is writable.
1363a19ae75SLionel SambucTrue
1373a19ae75SLionel Sambucindicates only that the write flag is on.
1383a19ae75SLionel SambucThe file is not writable on a read-only file
1393a19ae75SLionel Sambucsystem even if this test indicates true.
1403a19ae75SLionel Sambuc.It Fl x Ar file
1413a19ae75SLionel SambucTrue if
1423a19ae75SLionel Sambuc.Ar file
1433a19ae75SLionel Sambucexists and is executable.
1443a19ae75SLionel SambucTrue
1453a19ae75SLionel Sambucindicates only that the execute flag is on.
1463a19ae75SLionel SambucIf
1473a19ae75SLionel Sambuc.Ar file
1483a19ae75SLionel Sambucis a directory, true indicates that
1493a19ae75SLionel Sambuc.Ar file
1503a19ae75SLionel Sambuccan be searched.
1513a19ae75SLionel Sambuc.It Fl z Ar string
1523a19ae75SLionel SambucTrue if the length of
1533a19ae75SLionel Sambuc.Ar string
1543a19ae75SLionel Sambucis zero.
1553a19ae75SLionel Sambuc.It Fl L Ar file
1563a19ae75SLionel SambucTrue if
1573a19ae75SLionel Sambuc.Ar file
1583a19ae75SLionel Sambucexists and is a symbolic link.
1593a19ae75SLionel SambucThis operator is retained for compatibility with previous versions of
1603a19ae75SLionel Sambucthis program.
1613a19ae75SLionel SambucDo not rely on its existence; use
1623a19ae75SLionel Sambuc.Fl h
1633a19ae75SLionel Sambucinstead.
1643a19ae75SLionel Sambuc.It Fl O Ar file
1653a19ae75SLionel SambucTrue if
1663a19ae75SLionel Sambuc.Ar file
1673a19ae75SLionel Sambucexists and its owner matches the effective user id of this process.
1683a19ae75SLionel Sambuc.It Fl G Ar file
1693a19ae75SLionel SambucTrue if
1703a19ae75SLionel Sambuc.Ar file
1713a19ae75SLionel Sambucexists and its group matches the effective group id of this process.
1723a19ae75SLionel Sambuc.It Fl S Ar file
1733a19ae75SLionel SambucTrue if
1743a19ae75SLionel Sambuc.Ar file
1753a19ae75SLionel Sambucexists and is a socket.
1763a19ae75SLionel Sambuc.It Ar file1 Fl nt Ar file2
1773a19ae75SLionel SambucTrue if
1783a19ae75SLionel Sambuc.Ar file1
1793a19ae75SLionel Sambucexists and is newer than
1803a19ae75SLionel Sambuc.Ar file2 .
1813a19ae75SLionel Sambuc.It Ar file1 Fl ot Ar file2
1823a19ae75SLionel SambucTrue if
1833a19ae75SLionel Sambuc.Ar file1
1843a19ae75SLionel Sambucexists and is older than
1853a19ae75SLionel Sambuc.Ar file2 .
1863a19ae75SLionel Sambuc.It Ar file1 Fl ef Ar file2
1873a19ae75SLionel SambucTrue if
1883a19ae75SLionel Sambuc.Ar file1
1893a19ae75SLionel Sambucand
1903a19ae75SLionel Sambuc.Ar file2
1913a19ae75SLionel Sambucexist and refer to the same file.
1923a19ae75SLionel Sambuc.It Ar string
1933a19ae75SLionel SambucTrue if
1943a19ae75SLionel Sambuc.Ar string
1953a19ae75SLionel Sambucis not the null
1963a19ae75SLionel Sambucstring.
1973a19ae75SLionel Sambuc.It Ar \&s\&1 Cm \&= Ar \&s\&2
1983a19ae75SLionel SambucTrue if the strings
1993a19ae75SLionel Sambuc.Ar \&s\&1
2003a19ae75SLionel Sambucand
2013a19ae75SLionel Sambuc.Ar \&s\&2
2023a19ae75SLionel Sambucare identical.
2033a19ae75SLionel Sambuc.It Ar \&s\&1 Cm \&!= Ar \&s\&2
2043a19ae75SLionel SambucTrue if the strings
2053a19ae75SLionel Sambuc.Ar \&s\&1
2063a19ae75SLionel Sambucand
2073a19ae75SLionel Sambuc.Ar \&s\&2
2083a19ae75SLionel Sambucare not identical.
2093a19ae75SLionel Sambuc.It Ar \&s\&1 Cm \&\*[Lt] Ar \&s\&2
2103a19ae75SLionel SambucTrue if string
2113a19ae75SLionel Sambuc.Ar \&s\&1
2123a19ae75SLionel Sambuccomes before
2133a19ae75SLionel Sambuc.Ar \&s\&2
2143a19ae75SLionel Sambucbased on the ASCII value of their characters.
2153a19ae75SLionel Sambuc.It Ar \&s\&1 Cm \&\*[Gt] Ar \&s\&2
2163a19ae75SLionel SambucTrue if string
2173a19ae75SLionel Sambuc.Ar \&s\&1
2183a19ae75SLionel Sambuccomes after
2193a19ae75SLionel Sambuc.Ar \&s\&2
2203a19ae75SLionel Sambucbased on the ASCII value of their characters.
2213a19ae75SLionel Sambuc.It Ar \&n\&1 Fl \&eq Ar \&n\&2
2223a19ae75SLionel SambucTrue if the integers
2233a19ae75SLionel Sambuc.Ar \&n\&1
2243a19ae75SLionel Sambucand
2253a19ae75SLionel Sambuc.Ar \&n\&2
2263a19ae75SLionel Sambucare algebraically
2273a19ae75SLionel Sambucequal.
2283a19ae75SLionel Sambuc.It Ar \&n\&1 Fl \&ne Ar \&n\&2
2293a19ae75SLionel SambucTrue if the integers
2303a19ae75SLionel Sambuc.Ar \&n\&1
2313a19ae75SLionel Sambucand
2323a19ae75SLionel Sambuc.Ar \&n\&2
2333a19ae75SLionel Sambucare not
2343a19ae75SLionel Sambucalgebraically equal.
2353a19ae75SLionel Sambuc.It Ar \&n\&1 Fl \&gt Ar \&n\&2
2363a19ae75SLionel SambucTrue if the integer
2373a19ae75SLionel Sambuc.Ar \&n\&1
2383a19ae75SLionel Sambucis algebraically
2393a19ae75SLionel Sambucgreater than the integer
2403a19ae75SLionel Sambuc.Ar \&n\&2 .
2413a19ae75SLionel Sambuc.It Ar \&n\&1 Fl \&ge Ar \&n\&2
2423a19ae75SLionel SambucTrue if the integer
2433a19ae75SLionel Sambuc.Ar \&n\&1
2443a19ae75SLionel Sambucis algebraically
2453a19ae75SLionel Sambucgreater than or equal to the integer
2463a19ae75SLionel Sambuc.Ar \&n\&2 .
2473a19ae75SLionel Sambuc.It Ar \&n\&1 Fl \&lt Ar \&n\&2
2483a19ae75SLionel SambucTrue if the integer
2493a19ae75SLionel Sambuc.Ar \&n\&1
2503a19ae75SLionel Sambucis algebraically less
2513a19ae75SLionel Sambucthan the integer
2523a19ae75SLionel Sambuc.Ar \&n\&2 .
2533a19ae75SLionel Sambuc.It Ar \&n\&1 Fl \&le Ar \&n\&2
2543a19ae75SLionel SambucTrue if the integer
2553a19ae75SLionel Sambuc.Ar \&n\&1
2563a19ae75SLionel Sambucis algebraically less
2573a19ae75SLionel Sambucthan or equal to the integer
2583a19ae75SLionel Sambuc.Ar \&n\&2 .
2593a19ae75SLionel Sambuc.El
2603a19ae75SLionel Sambuc.Pp
2613a19ae75SLionel SambucThese primaries can be combined with the following operators:
2623a19ae75SLionel Sambuc.Bl -tag -width Ar
2633a19ae75SLionel Sambuc.It Cm \&! Ar expression
2643a19ae75SLionel SambucTrue if
2653a19ae75SLionel Sambuc.Ar expression
2663a19ae75SLionel Sambucis false.
2673a19ae75SLionel Sambuc.It Ar expression1 Fl a Ar expression2
2683a19ae75SLionel SambucTrue if both
2693a19ae75SLionel Sambuc.Ar expression1
2703a19ae75SLionel Sambucand
2713a19ae75SLionel Sambuc.Ar expression2
2723a19ae75SLionel Sambucare true.
2733a19ae75SLionel Sambuc.It Ar expression1 Fl o Ar expression2
2743a19ae75SLionel SambucTrue if either
2753a19ae75SLionel Sambuc.Ar expression1
2763a19ae75SLionel Sambucor
2773a19ae75SLionel Sambuc.Ar expression2
278*93184c84SSevan Janiyanis true.
2793a19ae75SLionel Sambuc.It Cm \&( Ar expression Cm \&)
2803a19ae75SLionel SambucTrue if
2813a19ae75SLionel Sambuc.Ar expression
2823a19ae75SLionel Sambucis true.
2833a19ae75SLionel Sambuc.El
2843a19ae75SLionel Sambuc.Pp
2853a19ae75SLionel SambucThe
2863a19ae75SLionel Sambuc.Fl a
2873a19ae75SLionel Sambucoperator has higher precedence than the
2883a19ae75SLionel Sambuc.Fl o
2893a19ae75SLionel Sambucoperator.
2903a19ae75SLionel Sambuc.Pp
2913a19ae75SLionel SambucNote that all file tests with the exception of
2923a19ae75SLionel Sambuc.Fl h
2933a19ae75SLionel Sambucand
2943a19ae75SLionel Sambuc.Fl L
2953a19ae75SLionel Sambucfollow symbolic links and thus evaluate the test for the file pointed at.
2963a19ae75SLionel Sambuc.Sh EXIT STATUS
2973a19ae75SLionel SambucThe
29884d9c625SLionel Sambuc.Nm
2993a19ae75SLionel Sambucutility exits with one of the following values:
3003a19ae75SLionel Sambuc.Bl -tag -width Ds
3013a19ae75SLionel Sambuc.It 0
3023a19ae75SLionel Sambuc.Ar expression
3033a19ae75SLionel Sambucevaluated to true.
3043a19ae75SLionel Sambuc.It 1
3053a19ae75SLionel Sambuc.Ar expression
3063a19ae75SLionel Sambucevaluated to false or was missing.
3073a19ae75SLionel Sambuc.It \*[Gt]1
3083a19ae75SLionel SambucAn error occurred.
3093a19ae75SLionel Sambuc.El
3103a19ae75SLionel Sambuc.Sh STANDARDS
3113a19ae75SLionel SambucThe
31284d9c625SLionel Sambuc.Nm
3133a19ae75SLionel Sambucutility implements a superset of the
3143a19ae75SLionel Sambuc.St -p1003.2
3153a19ae75SLionel Sambucspecification.
316*93184c84SSevan Janiyan.Sh HISTORY
317*93184c84SSevan JaniyanA
318*93184c84SSevan Janiyan.Nm
319*93184c84SSevan Janiyanutility appeared in
320*93184c84SSevan Janiyan.At v7 .
32184d9c625SLionel Sambuc.Sh CAVEATS
32284d9c625SLionel SambucThe
32384d9c625SLionel Sambuc.Nm
32484d9c625SLionel Sambucgrammar is inherently ambiguous.
32584d9c625SLionel SambucIn order to assure a degree of consistency, the cases described in
32684d9c625SLionel Sambuc.St -p1003.2
32784d9c625SLionel Sambucsection 4.62.4,
32884d9c625SLionel Sambucare evaluated consistently according to the rules specified in the
32984d9c625SLionel Sambucstandards document.
33084d9c625SLionel SambucAll other cases are subject to the ambiguity in the command semantics.
331