Debian Codegraph @

HTML/testsandcomparisons.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Tests and Comparisons: Alternatives</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
9 "><LINK
10 REL="HOME"
11 TITLE="Advanced Bash-Scripting Guide"
12 HREF="index.html"><LINK
13 REL="UP"
14 TITLE="Miscellany"
15 HREF="miscellany.html"><LINK
16 REL="PREVIOUS"
17 TITLE="Shell Wrappers"
18 HREF="wrapper.html"><LINK
19 REL="NEXT"
20 TITLE="Recursion: a script calling itself"
21 HREF="recursionsct.html"><META
22 HTTP-EQUIV="Content-Style-Type"
23 CONTENT="text/css"><LINK
24 REL="stylesheet"
25 HREF="common/kde-common.css"
26 TYPE="text/css"><META
27 HTTP-EQUIV="Content-Type"
28 CONTENT="text/html; charset=iso-8859-1"><META
29 HTTP-EQUIV="Content-Language"
30 CONTENT="en"><LINK
31 REL="stylesheet"
32 HREF="common/kde-localised.css"
33 TYPE="text/css"
34 TITLE="KDE-English"><LINK
35 REL="stylesheet"
36 HREF="common/kde-default.css"
37 TYPE="text/css"
38 TITLE="KDE-Default"></HEAD
39 ><BODY
40 CLASS="SECT1"
41 BGCOLOR="#FFFFFF"
42 TEXT="#000000"
43 LINK="#AA0000"
44 VLINK="#AA0055"
45 ALINK="#AA0000"
46 STYLE="font-family: sans-serif;"
47 ><DIV
48 CLASS="NAVHEADER"
49 ><TABLE
50 SUMMARY="Header navigation table"
51 WIDTH="100%"
52 BORDER="0"
53 CELLPADDING="0"
54 CELLSPACING="0"
55 ><TR
56 ><TH
57 COLSPAN="3"
58 ALIGN="center"
59 >Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
60 ></TR
61 ><TR
62 ><TD
63 WIDTH="10%"
64 ALIGN="left"
65 VALIGN="bottom"
66 ><A
67 HREF="wrapper.html"
68 ACCESSKEY="P"
69 >Prev</A
70 ></TD
71 ><TD
72 WIDTH="80%"
73 ALIGN="center"
74 VALIGN="bottom"
75 >Chapter 36. Miscellany</TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="bottom"
80 ><A
81 HREF="recursionsct.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="SECT1"
92 ><H1
93 CLASS="SECT1"
94 ><A
95 NAME="TESTSANDCOMPARISONS"
96 ></A
97 >36.3. Tests and Comparisons: Alternatives</H1
98 ><P
99 >For tests, the <A
100 HREF="tests.html#DBLBRACKETS"
101 >[[ ]]</A
102 >
103 construct may be more appropriate than <TT
104 CLASS="USERINPUT"
105 ><B
106 >[
107 ]</B
108 ></TT
109 >. Likewise, <A
110 HREF="comparison-ops.html#ICOMPARISON1"
111 >arithmetic
112 comparisons</A
113 > might benefit from the <A
114 HREF="dblparens.html"
115 >(( ))</A
116 > construct.
117
118 <TABLE
119 BORDER="0"
120 BGCOLOR="#E0E0E0"
121 WIDTH="100%"
122 ><TR
123 ><TD
124 ><PRE
125 CLASS="PROGRAMLISTING"
126 > 1&nbsp;a=8
127 2&nbsp;
128 3&nbsp;# All of the comparisons below are equivalent.
129 4&nbsp;test "$a" -lt 16 &#38;&#38; echo "yes, $a &#60; 16" # "and list"
130 5&nbsp;/bin/test "$a" -lt 16 &#38;&#38; echo "yes, $a &#60; 16"
131 6&nbsp;[ "$a" -lt 16 ] &#38;&#38; echo "yes, $a &#60; 16"
132 7&nbsp;[[ $a -lt 16 ]] &#38;&#38; echo "yes, $a &#60; 16" # Quoting variables within
133 8&nbsp;(( a &#60; 16 )) &#38;&#38; echo "yes, $a &#60; 16" # [[ ]] and (( )) not necessary.
134 9&nbsp;
135 10&nbsp;city="New York"
136 11&nbsp;# Again, all of the comparisons below are equivalent.
137 12&nbsp;test "$city" \&#60; Paris &#38;&#38; echo "Yes, Paris is greater than $city"
138 13&nbsp; # Greater ASCII order.
139 14&nbsp;/bin/test "$city" \&#60; Paris &#38;&#38; echo "Yes, Paris is greater than $city"
140 15&nbsp;[ "$city" \&#60; Paris ] &#38;&#38; echo "Yes, Paris is greater than $city"
141 16&nbsp;[[ $city &#60; Paris ]] &#38;&#38; echo "Yes, Paris is greater than $city"
142 17&nbsp; # Need not quote $city.
143 18&nbsp;
144 19&nbsp;# Thank you, S.C.</PRE
145 ></TD
146 ></TR
147 ></TABLE
148 ></P
149 ></DIV
150 ><DIV
151 CLASS="NAVFOOTER"
152 ><HR
153 ALIGN="LEFT"
154 WIDTH="100%"><TABLE
155 SUMMARY="Footer navigation table"
156 WIDTH="100%"
157 BORDER="0"
158 CELLPADDING="0"
159 CELLSPACING="0"
160 ><TR
161 ><TD
162 WIDTH="33%"
163 ALIGN="left"
164 VALIGN="top"
165 ><A
166 HREF="wrapper.html"
167 ACCESSKEY="P"
168 >Prev</A
169 ></TD
170 ><TD
171 WIDTH="34%"
172 ALIGN="center"
173 VALIGN="top"
174 ><A
175 HREF="index.html"
176 ACCESSKEY="H"
177 >Home</A
178 ></TD
179 ><TD
180 WIDTH="33%"
181 ALIGN="right"
182 VALIGN="top"
183 ><A
184 HREF="recursionsct.html"
185 ACCESSKEY="N"
186 >Next</A
187 ></TD
188 ></TR
189 ><TR
190 ><TD
191 WIDTH="33%"
192 ALIGN="left"
193 VALIGN="top"
194 >Shell Wrappers</TD
195 ><TD
196 WIDTH="34%"
197 ALIGN="center"
198 VALIGN="top"
199 ><A
200 HREF="miscellany.html"
201 ACCESSKEY="U"
202 >Up</A
203 ></TD
204 ><TD
205 WIDTH="33%"
206 ALIGN="right"
207 VALIGN="top"
208 >Recursion: a script calling itself</TD
209 ></TR
210 ></TABLE
211 ></DIV
212 ></BODY
213 ></HTML
214 >