270-272.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 158 行

HTML
158
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Shell Programming</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=14//-->

<!--PAGES=270-272//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="269-270.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="272-275.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">The tcsh Equivalent of the test Command</FONT></H4>

<P>The <TT>tcsh</TT> does not have a <TT>test</TT> command, but it supports the same function using expressions. The expression operators that <TT>tcsh</TT> supports are almost identical to those supported by the C language. These expressions are used mostly in the <TT>if</TT> and <TT>while</TT> commands, which are covered later in this chapter in the &#147;Conditional Statements&#148; and &#147;Iteration Statements&#148; sections.</P>

<P>The <TT>tcsh</TT> expressions support the same kind of operators as the <TT>bash</TT> and <TT>pdksh test</TT> command. These are integer, string, file, and logical expressions. The integer operators supported by <TT>tcsh</TT> expressions are listed in Table 14.6.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 14.6.</B> The <TT>tcsh</TT> expression integer operators.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH ALIGN="LEFT" WIDTH="30%">Operator

<TH ALIGN="LEFT" WIDTH="70%">Meaning

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>int1 &lt;= int2</TT>

<TD>Returns True if int1 is less than or equal to int2.

<TR>

<TD><TT>int1 &gt;= int2</TT>

<TD>Returns True if int1 is greater than or equal to int2.

<TR>

<TD><TT>int1 &lt; int2</TT>

<TD>Returns True if int1 is less than int2.

<TR>

<TD><TT>int1 &gt; int2</TT>

<TD>Returns True if int1 is greater than int2.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>The string operators that <TT>tcsh</TT> expressions support are listed in Table 14.7.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 14.7.</B> The <TT>tcsh</TT> expression string operators.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH ALIGN="LEFT" WIDTH="30%">Operator

<TH ALIGN="LEFT" WIDTH="70%">Meaning

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>str1 == str2</TT>

<TD>Returns True if <TT>str1</TT> is equal to <TT>str2</TT>.

<TR>

<TD><TT>str1 != str2</TT>

<TD>Returns True if <TT>str1</TT> is not equal to <TT>str2</TT>.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>The file operators that <TT>tcsh</TT> expressions support are listed in Table 14.8.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT>T<B>able 14.8.</B> The <TT>tcsh</TT> expression file operators.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH ALIGN="LEFT" WIDTH="30%">Operator

<TH ALIGN="LEFT" WIDTH="70%">Meaning

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>-r file</TT>

<TD>Returns True if file is readable.

<TR>

<TD><TT>-w file</TT>

<TD>Returns True if file is writable.

<TR>

<TD><TT>-x file</TT>

<TD>Returns True if file is executable.

<TR>

<TD><TT>-e file</TT>

<TD>Returns True if file exists.

<TR>

<TD><TT>-o file</TT>

<TD>Returns True if file is owned by the current user.

<TR>

<TD><TT>-z file</TT>

<TD>Returns True if file is of size 0.

<TR>

<TD><TT>-f file</TT>

<TD>Returns True if file is a regular file.

<TR>

<TD><TT>-d file</TT>

<TD>Returns True if <TT>file</TT> is a directory file.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>The logical operators that <TT>tcsh</TT> expressions support are listed in Table 14.9.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 14.9.</B> The <TT>tcsh</TT> expression logical operators.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH ALIGN="LEFT" WIDTH="30%">Operator

<TH ALIGN="LEFT" WIDTH="70%">Meaning

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>exp1 || exp2</TT>

<TD>Returns True if <TT>exp1</TT> is true or if <TT>exp2</TT> is true.

<TR>

<TD><TT>exp1 && exp2</TT>

<TD>Returns True if <TT>exp1</TT> is true and <TT>exp2</TT> is true.

<TR>

<TD><TT>! exp</TT>

<TD>Returns True if <TT>exp</TT> is not true.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<H3><A NAME="Heading10"></A><FONT COLOR="#000077">Conditional Statements</FONT></H3>

<P>The <TT>bash</TT>, <TT>pdksh</TT>, and <TT>tcsh</TT> each have two forms of conditional statements. These are the <TT>if</TT> statement and the <TT>case</TT> statement. These statements are used to execute different parts of your shell program depending on whether certain conditions are true. As with most statements, the syntax for these statements is slightly different between the different shells.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="269-270.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="272-275.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?