265 lines
7.6 KiB
HTML
265 lines
7.6 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content=
|
|
"text/html; charset=utf-8">
|
|
<title>test - Evaluate expression</title>
|
|
<LINK rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</HEAD>
|
|
<body bgcolor="#FFFFFF">
|
|
<!-- Java sync-link -->
|
|
<SCRIPT LANGUAGE="Javascript" SRC="../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
|
|
|
|
|
|
|
<h2>test - Evaluate expression</h2>
|
|
|
|
<strong>Synopsis</strong>
|
|
|
|
<p>test <em>expression</em></p>
|
|
|
|
<p>[ <em>expression</em> ]</p>
|
|
|
|
<p><strong>Description</strong></p>
|
|
|
|
<p>The <strong>test</strong> utility checks the type of a file,
|
|
checks permissions on files, compares two strings, or compares two
|
|
arithmetic expressions.</p>
|
|
|
|
<p>The <strong>test</strong> utility tests conditions for files using
|
|
the following primaries:</p>
|
|
|
|
<dl>
|
|
<dt><strong>-b</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a block special file.</dd>
|
|
|
|
<dt><strong>-c</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a character special file.</dd>
|
|
|
|
<dt><strong>-d</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a directory.</dd>
|
|
|
|
<dt><strong>-e</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists regardless of type.</dd>
|
|
|
|
<dt><strong>-f</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a regular file.</dd>
|
|
|
|
<dt><strong>-g</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and its set group id flag is set.</dd>
|
|
|
|
<dt>
|
|
<strong>-G</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is owned by the effective group id.
|
|
</dd>
|
|
|
|
<dt><strong>-h</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a symbolic link.</dd>
|
|
|
|
<dt><strong>-k</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and its restricted deletion flag is set.</dd>
|
|
|
|
<dt><strong>-L</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a symbolic link.</dd>
|
|
|
|
<dt><strong>-N</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a native object.</dd>
|
|
|
|
<dt>
|
|
<strong>-O</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is owned by the effective user id.
|
|
</dd>
|
|
|
|
<dt><strong>-p</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a pipe.</dd>
|
|
|
|
<dt><strong>-r</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is readable.</dd>
|
|
|
|
<dt><strong>-s</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and has a size greater than zero.</dd>
|
|
|
|
<dt><strong>-S</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is a socket.</dd>
|
|
|
|
<dt><strong>-u</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and its set user id flag is set.</dd>
|
|
|
|
<dt><strong>-w</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists and is writable.</dd>
|
|
|
|
<dt><strong>-x</strong> <em>file</em></dt>
|
|
<dd>True if <em>file</em> exists
|
|
and is executable. This only means that the execute bit is on. If
|
|
<em>file</em> is a directory, the directory can be searched.</dd>
|
|
|
|
<dt>
|
|
<em>file1</em> <strong>-ef</strong> <em>file2</em></dt>
|
|
<dd>True if <em>file1</em> and <em>file2</em> are different names for the same
|
|
file (they have the same device and inode numbers).</dd>
|
|
|
|
<dt><em>file1</em> <strong>-nt</strong> <em>file2</em></dt>
|
|
<dd>True if <em>file1</em> is newer than <em>file2</em> or <em>file2</em> does not exist.</dd>
|
|
|
|
<dt><em>file1</em> <strong>-ot</strong> <em>file2</em></dt>
|
|
<dd>True if <em>file1</em> is older than <em>file2</em> or <em>file2</em> does not exist.
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
<p>The <strong>test</strong> utility tests conditions for checking status
|
|
using the following primaries:</p>
|
|
|
|
<dl>
|
|
|
|
<dt>
|
|
<strong>-o</strong> <em>optname</em></dt>
|
|
<dd>True if shell option <em>optname</em> is enabled.
|
|
</dd>
|
|
|
|
<dt><strong>-t</strong> <em>fd</em></dt>
|
|
<dd>True if file descriptor <em> fd</em> is open and associated with a terminal.</dd>
|
|
|
|
</dl>
|
|
|
|
<p>The <strong>test</strong> utility tests conditions for comparing strings
|
|
using the following primaries:</p>
|
|
|
|
<dl>
|
|
|
|
<dt><strong>-n</strong> <em>string</em></dt>
|
|
<dd>True if the length of <em> string</em> is non-zero.</dd>
|
|
|
|
<dt><strong>-z</strong> <em>string</em></dt>
|
|
<dd>True if the length of <em> string</em> is zero.</dd>
|
|
|
|
<dt><em>string</em></dt>
|
|
<dd>True if <em>string</em> is not the null string.</dd>
|
|
|
|
<dt><em>string1</em> <strong>=</strong> <em>string2</em></dt>
|
|
<dd>True if the strings are identical.</dd>
|
|
|
|
<dt>
|
|
<em>string1</em> <strong>==</strong> <em>string2</em></dt>
|
|
<dd>True if the strings are identical.
|
|
</dd>
|
|
|
|
<dt><em>string1</em> <strong>!=</strong> <em>string2</em></dt>
|
|
<dd>True if the strings are not identical.</dd>
|
|
|
|
<dt>
|
|
<em>string1</em> <strong><</strong> <em>string2</em></dt>
|
|
<dd>True if <em>string1</em> sorts before <em>string2</em> in the collation
|
|
sequence of the current locale.</dd>
|
|
|
|
<dt><em>string1</em> <strong>></strong> <em>string2</em></dt>
|
|
<dd>True if <em>string1</em> sorts after <em>string2</em> in the collation
|
|
sequence of the current locale.
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
<p>The <strong>test</strong> utility tests conditions for comparing
|
|
<a href="arithexp.htm">arithmetic expressions</a> using
|
|
the following primaries:</p>
|
|
|
|
<dl>
|
|
|
|
<dt><em>exp1</em> <strong>-eq</strong> <em>exp2</em></dt>
|
|
<dd>True if the arithmetic expressions are equal.</dd>
|
|
|
|
<dt><em>exp1</em> <strong>-ne</strong> <em>exp2</em></dt>
|
|
<dd>True if the arithmetic expressions are not equal.</dd>
|
|
|
|
<dt><em>exp1</em> <strong>-gt</strong> <em>exp2</em></dt>
|
|
<dd>True if the first arithmetic expression is greater than the second arithmetic expression.</dd>
|
|
|
|
<dt><em>exp1</em> <strong>-ge</strong> <em>exp2</em></dt>
|
|
<dd>True if the first arithmetic expression is greater than or equal to the second arithmetic expression.</dd>
|
|
|
|
<dt><em>exp1</em> <strong>-lt</strong> <em>exp2</em></dt>
|
|
<dd>True if the first arithmetic expression is less than the second arithmetic expression.</dd>
|
|
|
|
<dt><em>exp1</em> <strong>-le</strong> <em>exp2</em></dt>
|
|
<dd>True if the first arithmetic expression is less than or equal to the second arithmetic expression.</dd>
|
|
|
|
</dl>
|
|
|
|
<p>The above primaries can be combined to form complex expressions
|
|
using the following operators:</p>
|
|
|
|
<ul>
|
|
<li><strong>!</strong> <em>expr</em> True if <em>expr</em> is
|
|
false.</li>
|
|
|
|
<li><em>expr1</em> <strong>-a</strong> <em>expr2</em> True if both
|
|
expressions are true.</li>
|
|
|
|
<li><em>expr1</em> <strong>&</strong> <em>expr2</em> True if
|
|
both expressions are true.</li>
|
|
|
|
<li>
|
|
<em>expr1</em> <strong>&&</strong> <em>expr2</em> True if
|
|
both expressions are true.
|
|
</li>
|
|
|
|
<li><em>expr1</em> <strong>-o</strong> <em>expr2</em> True if
|
|
either expression is true.</li>
|
|
|
|
<li><em>expr</em>1 <strong>|</strong> <em>expr2</em> True if either
|
|
expression is true.</li>
|
|
|
|
<li>
|
|
<em>expr</em>1 <strong>||</strong> <em>expr2</em> True if either
|
|
expression is true.
|
|
</li>
|
|
|
|
<li><strong>(</strong><em>expr</em><strong>)</strong> Parentheses
|
|
are for grouping.</li>
|
|
</ul>
|
|
|
|
<p>The <strong>-a</strong>, <strong>&</strong>, and <strong>&&</strong> operators
|
|
have higher precedence than the <strong>-o</strong>, <strong>
|
|
|</strong> operators, and <strong>||</strong> operators.</p>
|
|
|
|
<p><strong>Options</strong></p>
|
|
|
|
<p>See above.</p>
|
|
|
|
<p><strong>Operands</strong></p>
|
|
|
|
<p>All operators and flags are separate arguments.</p>
|
|
|
|
<p><strong>Exit Status</strong></p>
|
|
|
|
<ul>
|
|
<li>0 when <em>expression</em> is true.</li>
|
|
|
|
<li>1 when <em>expression</em> is false.</li>
|
|
|
|
<li>>1 when there is an error.</li>
|
|
</ul>
|
|
|
|
<strong>Examples</strong>
|
|
|
|
<ol>
|
|
<li>See if /home is a directory:
|
|
<pre>
|
|
test -d /home
|
|
</pre></li>
|
|
|
|
<li>See if one integer is less than or equal to another:
|
|
<pre>
|
|
test "$index" -le "$count"
|
|
</pre></li>
|
|
|
|
<li>See if two strings are equal:
|
|
<pre>
|
|
test "$REPLY" = "Yes"
|
|
</pre></li>
|
|
</ol>
|
|
</body>
|
|
</html>
|
|
|