This commit is contained in:
sylvestre
2023-05-03 02:44:30 +00:00
parent ae84e6b67a
commit f14a1bc203
4 changed files with 232 additions and 2 deletions
+115
View File
@@ -8411,8 +8411,123 @@ With no FILE, or when FILE is -, read standard input.</p>
<div class="version">v0.0.18
</div>
</div>
<pre><code>test EXPRESSION
test
test EXPRESSION ]
test ]
test OPTION
</code></pre>
<p>Check file types and compare values.</p>
<h2 id="options-99"><a class="header" href="#options-99">Options</a></h2>
<dl></dl>
<p>Exit with the status determined by <code>EXPRESSION</code>.</p>
<p>An omitted <code>EXPRESSION</code> defaults to false.
Otherwise, <code>EXPRESSION</code> is true or false and sets exit status. </p>
<p>It is one of:</p>
<ul>
<li>( EXPRESSION ) <code>EXPRESSION</code> is true</li>
<li>! EXPRESSION <code>EXPRESSION</code> is false</li>
<li>EXPRESSION1 -a EXPRESSION2 both <code>EXPRESSION1</code> and <code>EXPRESSION2</code> are true</li>
<li>EXPRESSION1 -o EXPRESSION2 either <code>EXPRESSION1</code> or <code>EXPRESSION2</code> is true</li>
</ul>
<p>String operations:</p>
<ul>
<li>-n STRING the length of <code>STRING</code> is nonzero</li>
<li>STRING equivalent to -n <code>STRING</code></li>
<li>-z STRING the length of <code>STRING</code> is zero</li>
<li>STRING1 = STRING2 the strings are equal</li>
<li>STRING1 != STRING2 the strings are not equal</li>
</ul>
<p>Integer comparisons:</p>
<ul>
<li>INTEGER1 -eq INTEGER2 <code>INTEGER1</code> is equal to <code>INTEGER2</code></li>
<li>INTEGER1 -ge INTEGER2 <code>INTEGER1</code> is greater than or equal to <code>INTEGER2</code></li>
<li>INTEGER1 -gt INTEGER2 <code>INTEGER1</code> is greater than <code>INTEGER2</code></li>
<li>INTEGER1 -le INTEGER2 <code>INTEGER1</code> is less than or equal to <code>INTEGER2</code></li>
<li>INTEGER1 -lt INTEGER2 <code>INTEGER1</code> is less than <code>INTEGER2</code></li>
<li>INTEGER1 -ne INTEGER2 <code>INTEGER1</code> is not equal to <code>INTEGER2</code></li>
</ul>
<p>File operations:</p>
<ul>
<li>
<p>FILE1 -ef FILE2 <code>FILE1</code> and <code>FILE2</code> have the same device and inode numbers</p>
</li>
<li>
<p>FILE1 -nt FILE2 <code>FILE1</code> is newer (modification date) than <code>FILE2</code></p>
</li>
<li>
<p>FILE1 -ot FILE2 <code>FILE1</code> is older than <code>FILE2</code></p>
</li>
<li>
<p>-b FILE <code>FILE</code> exists and is block special</p>
</li>
<li>
<p>-c FILE <code>FILE</code> exists and is character special</p>
</li>
<li>
<p>-d FILE <code>FILE</code> exists and is a directory</p>
</li>
<li>
<p>-e FILE <code>FILE</code> exists</p>
</li>
<li>
<p>-f FILE <code>FILE</code> exists and is a regular file</p>
</li>
<li>
<p>-g FILE <code>FILE</code> exists and is set-group-ID</p>
</li>
<li>
<p>-G FILE <code>FILE</code> exists and is owned by the effective group ID</p>
</li>
<li>
<p>-h FILE <code>FILE</code> exists and is a symbolic link (same as -L)</p>
</li>
<li>
<p>-k FILE <code>FILE</code> exists and has its sticky bit set</p>
</li>
<li>
<p>-L FILE <code>FILE</code> exists and is a symbolic link (same as -h)</p>
</li>
<li>
<p>-N FILE <code>FILE</code> exists and has been modified since it was last read</p>
</li>
<li>
<p>-O FILE <code>FILE</code> exists and is owned by the effective user ID</p>
</li>
<li>
<p>-p FILE <code>FILE</code> exists and is a named pipe</p>
</li>
<li>
<p>-r FILE <code>FILE</code> exists and read permission is granted</p>
</li>
<li>
<p>-s FILE <code>FILE</code> exists and has a size greater than zero</p>
</li>
<li>
<p>-S FILE <code>FILE</code> exists and is a socket</p>
</li>
<li>
<p>-t FD <code>file</code> descriptor <code>FD</code> is opened on a terminal</p>
</li>
<li>
<p>-u FILE <code>FILE</code> exists and its set-user-ID bit is set</p>
</li>
<li>
<p>-w FILE <code>FILE</code> exists and write permission is granted</p>
</li>
<li>
<p>-x FILE <code>FILE</code> exists and execute (or search) permission is granted</p>
</li>
</ul>
<p>Except for <code>-h</code> and <code>-L</code>, all FILE-related tests dereference (follow) symbolic links.
Beware that parentheses need to be escaped (e.g., by backslashes) for shells.
<code>INTEGER</code> may also be -l <code>STRING</code>, which evaluates to the length of <code>STRING</code>.</p>
<p>NOTE: Binary <code>-a</code> and <code>-o</code> are inherently ambiguous.
Use <code>test EXPR1 &amp;&amp; test EXPR2</code> or <code>test EXPR1 || test EXPR2</code> instead.</p>
<p>NOTE: <code>[</code> honors the <code>--help</code> and <code>--version</code> options, but test does not.
test treats each of those as it treats any other nonempty <code>STRING</code>.</p>
<p>NOTE: your shell may have its own version of <code>test</code> and/or <code>[</code>, which usually supersedes the version described here.
Please refer to your shell's documentation for details about the options it supports.</p>
<h2 id="examples-89"><a class="header" href="#examples-89">Examples</a></h2>
<p>Test if a given variable is equal to a given string:</p>
<pre><code class="language-shell">test &quot;{{$MY_VAR}}&quot; == &quot;{{/bin/zsh}}&quot;
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+115
View File
@@ -179,8 +179,123 @@
<div class="version">v0.0.18
</div>
</div>
<pre><code>test EXPRESSION
test
test EXPRESSION ]
test ]
test OPTION
</code></pre>
<p>Check file types and compare values.</p>
<h2 id="options"><a class="header" href="#options">Options</a></h2>
<dl></dl>
<p>Exit with the status determined by <code>EXPRESSION</code>.</p>
<p>An omitted <code>EXPRESSION</code> defaults to false.
Otherwise, <code>EXPRESSION</code> is true or false and sets exit status. </p>
<p>It is one of:</p>
<ul>
<li>( EXPRESSION ) <code>EXPRESSION</code> is true</li>
<li>! EXPRESSION <code>EXPRESSION</code> is false</li>
<li>EXPRESSION1 -a EXPRESSION2 both <code>EXPRESSION1</code> and <code>EXPRESSION2</code> are true</li>
<li>EXPRESSION1 -o EXPRESSION2 either <code>EXPRESSION1</code> or <code>EXPRESSION2</code> is true</li>
</ul>
<p>String operations:</p>
<ul>
<li>-n STRING the length of <code>STRING</code> is nonzero</li>
<li>STRING equivalent to -n <code>STRING</code></li>
<li>-z STRING the length of <code>STRING</code> is zero</li>
<li>STRING1 = STRING2 the strings are equal</li>
<li>STRING1 != STRING2 the strings are not equal</li>
</ul>
<p>Integer comparisons:</p>
<ul>
<li>INTEGER1 -eq INTEGER2 <code>INTEGER1</code> is equal to <code>INTEGER2</code></li>
<li>INTEGER1 -ge INTEGER2 <code>INTEGER1</code> is greater than or equal to <code>INTEGER2</code></li>
<li>INTEGER1 -gt INTEGER2 <code>INTEGER1</code> is greater than <code>INTEGER2</code></li>
<li>INTEGER1 -le INTEGER2 <code>INTEGER1</code> is less than or equal to <code>INTEGER2</code></li>
<li>INTEGER1 -lt INTEGER2 <code>INTEGER1</code> is less than <code>INTEGER2</code></li>
<li>INTEGER1 -ne INTEGER2 <code>INTEGER1</code> is not equal to <code>INTEGER2</code></li>
</ul>
<p>File operations:</p>
<ul>
<li>
<p>FILE1 -ef FILE2 <code>FILE1</code> and <code>FILE2</code> have the same device and inode numbers</p>
</li>
<li>
<p>FILE1 -nt FILE2 <code>FILE1</code> is newer (modification date) than <code>FILE2</code></p>
</li>
<li>
<p>FILE1 -ot FILE2 <code>FILE1</code> is older than <code>FILE2</code></p>
</li>
<li>
<p>-b FILE <code>FILE</code> exists and is block special</p>
</li>
<li>
<p>-c FILE <code>FILE</code> exists and is character special</p>
</li>
<li>
<p>-d FILE <code>FILE</code> exists and is a directory</p>
</li>
<li>
<p>-e FILE <code>FILE</code> exists</p>
</li>
<li>
<p>-f FILE <code>FILE</code> exists and is a regular file</p>
</li>
<li>
<p>-g FILE <code>FILE</code> exists and is set-group-ID</p>
</li>
<li>
<p>-G FILE <code>FILE</code> exists and is owned by the effective group ID</p>
</li>
<li>
<p>-h FILE <code>FILE</code> exists and is a symbolic link (same as -L)</p>
</li>
<li>
<p>-k FILE <code>FILE</code> exists and has its sticky bit set</p>
</li>
<li>
<p>-L FILE <code>FILE</code> exists and is a symbolic link (same as -h)</p>
</li>
<li>
<p>-N FILE <code>FILE</code> exists and has been modified since it was last read</p>
</li>
<li>
<p>-O FILE <code>FILE</code> exists and is owned by the effective user ID</p>
</li>
<li>
<p>-p FILE <code>FILE</code> exists and is a named pipe</p>
</li>
<li>
<p>-r FILE <code>FILE</code> exists and read permission is granted</p>
</li>
<li>
<p>-s FILE <code>FILE</code> exists and has a size greater than zero</p>
</li>
<li>
<p>-S FILE <code>FILE</code> exists and is a socket</p>
</li>
<li>
<p>-t FD <code>file</code> descriptor <code>FD</code> is opened on a terminal</p>
</li>
<li>
<p>-u FILE <code>FILE</code> exists and its set-user-ID bit is set</p>
</li>
<li>
<p>-w FILE <code>FILE</code> exists and write permission is granted</p>
</li>
<li>
<p>-x FILE <code>FILE</code> exists and execute (or search) permission is granted</p>
</li>
</ul>
<p>Except for <code>-h</code> and <code>-L</code>, all FILE-related tests dereference (follow) symbolic links.
Beware that parentheses need to be escaped (e.g., by backslashes) for shells.
<code>INTEGER</code> may also be -l <code>STRING</code>, which evaluates to the length of <code>STRING</code>.</p>
<p>NOTE: Binary <code>-a</code> and <code>-o</code> are inherently ambiguous.
Use <code>test EXPR1 &amp;&amp; test EXPR2</code> or <code>test EXPR1 || test EXPR2</code> instead.</p>
<p>NOTE: <code>[</code> honors the <code>--help</code> and <code>--version</code> options, but test does not.
test treats each of those as it treats any other nonempty <code>STRING</code>.</p>
<p>NOTE: your shell may have its own version of <code>test</code> and/or <code>[</code>, which usually supersedes the version described here.
Please refer to your shell's documentation for details about the options it supports.</p>
<h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
<p>Test if a given variable is equal to a given string:</p>
<pre><code class="language-shell">test &quot;{{$MY_VAR}}&quot; == &quot;{{/bin/zsh}}&quot;