home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / info / awksplmn.txt < prev    next >
Encoding:
Internet Message Format  |  1990-02-02  |  19.8 KB

  1. From sparkyfs!ames!sun-barr!cs.utexas.edu!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!wuarchive!udel!burdvax!lang Thu Nov 16 16:25:12 PST 1989
  2.  
  3. It's time once again to post to this group a document that I have
  4. which explains some important things about (vanilla) AWK
  5. that are not elsewhere documented....
  6.  
  7. ****************************************************************
  8.  
  9. \" to print this document, do ditroff -ms -Pip2 awk.supp
  10. .RP
  11. .TL
  12. .B
  13. A Supplemental Document For AWK
  14. .sp
  15. .R
  16. - or -
  17. .sp
  18. .I
  19. Things Al, Pete, And Brian Didn't Mention Much
  20. .R
  21. .AU
  22. John W. Pierce
  23. .AI
  24. Department of Chemistry
  25. University of California, San Diego
  26. La Jolla, California  92093
  27. jwp%chem@sdcsvax.ucsd.edu
  28. .AB
  29. As
  30. .B awk
  31. and its documentation are distributed with
  32. .I
  33. 4.2 BSD UNIX*
  34. .R
  35. there are a number of bugs, undocumented features,
  36. and features that are touched on so briefly in the
  37. documentation that the casual user may
  38. not realize their full significance.  While this document
  39. applies primarily to the \fI4.2 BSD\fR version of \fIUNIX\fR,
  40. it is known that the \fI4.3 BSD\fR version does not have
  41. all of the bugs fixed, and that it does not have updated
  42. documentation.  The situation with respect to the versions
  43. of \fBawk\fR distributed with other versions \fIUNIX\fR and
  44. similar systems is unknown to the author.
  45. .FS
  46. *UNIX is a trademark of AT&T
  47. .FE
  48. .AE
  49. .LP
  50. In this document references to "the user manual" mean
  51. .I
  52. Awk - A Pattern Scanning and Processing Language (Second Edition)
  53. .R
  54. by Aho, Kernighan, and Weinberger.  References to "awk(1)" mean
  55. the entry for
  56. .B awk
  57. in the
  58. .I
  59. UNIX Programmer's Manual, 4th Berkeley Distribution.
  60. .R
  61. References to "the documentation" mean both of those.
  62. .LP
  63. In most examples, the outermost set of braces ('{ }') have been
  64. ommitted.  They would, of course, be necessary in real scripts.
  65. .NH
  66. Known Bugs
  67. .LP
  68. There are three main bugs known to me.  They involve:
  69. .IP
  70. Assignment to input fields.
  71. .IP
  72. Piping output to a program from within an \fBawk\fR script.
  73. .IP
  74. Using '*' in \fIprintf\fR field width and precision specifications
  75. does not work, nor do '\\f' and '\\b' print formfeed and backspace
  76. respectively.
  77. .NH 2
  78. Assignment to Input Fields
  79. .LP
  80. [This problem is partially fixed in \fI4.3BSD\fR;
  81. see the last paragraph of this section regarding the unfixed portion.]
  82. .LP
  83. The user manual states that input fields may be objects of assignment
  84. statements.  Given the input line
  85. .DS
  86. field_one field_two field_three
  87. .DE
  88. the script
  89. .DS
  90. $2 = "new_field_2"
  91. print $0
  92. .DE
  93. should print
  94. .DS
  95. field_one new_field_2 field_three
  96. .DE
  97. .LP
  98. This does not work; it will print
  99. .DS
  100. field_one field_two field_three
  101. .DE
  102. That is, the script will behave as if the
  103. assignment to $2 had not been made.  However,
  104. explicitly referencing an "assigned to" field
  105. .I does
  106. recognize that the assignment has been made.
  107. If the script
  108. .DS
  109. $2 = "new_field_2"
  110. print $1, $2, $3
  111. .DE
  112. is given the same input it will [properly] print
  113. .DS
  114. field_one new_field_2 field_three
  115. .DE
  116. Therefore, you can
  117. get around this bug with, e.g.,
  118. .DS
  119. $2 = "new_field_2"
  120. output = $1                       # Concatenate output fields
  121. for(i = 2; i <= NF; ++i)          # into a single output line
  122.     output = output OFS $i    # with OFS between fields
  123. print output
  124. .DE
  125. .LP
  126. In \fI4.3BSD\fR, this bug has been fixed to the extent that
  127. the failing example above works correctly.  However, a script like
  128. .DS
  129. $2 = "new_field_2"
  130. var = $0
  131. print var
  132. .DE
  133. still gives incorrect output.  This problem can be bypassed by using
  134. .DS
  135. \fIvar\fR = sprintf("%s", $0)
  136. .DE
  137. instead of "\fIvar\fR = $0"; \fIvar\fR will have the correct value.
  138. .NH 2
  139. Piping Output to a Program
  140. .LP
  141. [This problem appears to have been fixed in \fI4.3BSD\fR,
  142. but that has not been exhaustively tested.]
  143. .LP
  144. The user manual states that
  145. .I print
  146. and
  147. .I printf
  148. statements may write to a program using, e.g.,
  149. .DS
  150. print | "\fIcommand\fR"
  151. .DE
  152. This would pipe the output into \fIcommand\fR, and it
  153. does work.  However, you should be aware that this causes
  154. .B awk
  155. to spawn a child process (\fIcommand\fR), and that it
  156. .I
  157. does not
  158. .R
  159. wait for the child to exit before it exits itself.  In the case of a
  160. "slow" command like
  161. .B sort,
  162. .B awk
  163. may exit before
  164. .I command
  165. has finished.
  166. .LP
  167. This can cause problems in, for example, a shell script that
  168. depends on everything done by
  169. .B awk
  170. being finished before the next shell command is executed.
  171. Consider the shell script
  172. .DS
  173. awk -f awk_script input_file
  174. mv sorted_output somewhere_else
  175. .DE
  176. and the
  177. .B awk
  178. script
  179. .DS
  180. print output_line | "sort -o sorted_output"
  181. .DE
  182. If
  183. .I input_file
  184. is large
  185. .B awk
  186. will exit long before
  187. .B sort
  188. is finished.  That means that the
  189. .B mv
  190. command will be executed before
  191. .B sort
  192. is finished, and the result is unlikely to be what you wanted.
  193. Other than fixing the source, there is no way to avoid this
  194. problem except to handle such pipes outside of the awk script, e.g.
  195. .DS
  196. awk -f awk_file input_file | sort -o sorted_output
  197. mv sorted_output somewhere_else
  198. .DE
  199. which is not wholly satisfactory.
  200. .LP
  201. See
  202. .I
  203. Sketchily Documented Features
  204. .R
  205. below for other considerations in redirecting
  206. output from within an
  207. .B awk
  208. script.
  209. .NH 2
  210. Printf and '*', '\\f', and '\\b'
  211. .LP
  212. The document says that the \fIprintf\fR function provided is
  213. identical to the \fIprintf\fR provided by the \fIC\fR language
  214. \fBstdio\fR package.  This is incorrect:  '*' cannot be used to
  215. specify a field width or precision, and '\\f' and '\\b' cannot
  216. be used to print formfeeds and backspaces.
  217. .LP
  218. The command
  219. .DS
  220. printf("%*.s", len, string)
  221. .DE
  222. will cause a core dump.  Given \fBawk\fR's age, it is likely
  223. that its \fIprintf\fR was written well before the use of '*'
  224. for specifying field width and precision appeared in the \fBstdio\fR
  225. library's \fIprintf\fR.  Another possibility is that it wasn't
  226. implemented because it isn't really needed to achieve the same effect.
  227. .LP
  228. To accomplish this effect, you can utilize the fact that \fBawk\fR
  229. concatenates variables before it does any other processing on them.
  230. For example, assume a script has two variables \fIwid\fR and
  231. \fIprec\fR which control the width and precision used for printing
  232. another variable \fIval\fI:
  233. .DS
  234. [code to set "wid", "prec", and "val"]
  235.  
  236. printf("%" wid "." prec "d\en", val)
  237. .DE
  238. If, for example, \fIwid\fR is 8 and \fIprec\fR is 3, then /fBawk\fR
  239. will concatenate everything to the left of the comma in
  240. the \fIprintf\fR statement, and the statement will really be
  241. .DS
  242. printf(%8.3d\en, val)
  243. .DE
  244. These could, of course, been assigned to some variable \fIfmt\fR before
  245. being used:
  246. .DS
  247. fmt = "%" wid "." prec "d"
  248.  
  249. printf(fmt "\en", val)
  250. .DE
  251. Note, however, that the newline ("\en") in the second form \fIcannot\fR
  252. be included in the assignment to \fIfmt\fR.
  253. .LP
  254. To allow use of '\\f' and '\\b', \fBawk\fR's \fIlex\fR script must
  255. be changed.  This is trivial to do (it is done at the point
  256. where '\\n' and '\\t' are processed), but requires having source
  257. code.  [I have fixed this and have not seen any unwanted effects.]
  258. # .bp
  259. .NH
  260. Undocumented Features
  261. .LP
  262. There are several undocumented features:
  263. .IP
  264. Variable values may be established on the command line.
  265. .IP
  266. A
  267. .B getline
  268. function exists that reads the next input line and starts processing it
  269. immediately.
  270. .IP
  271. Regular expressions accept octal representations of characters.
  272. .IP
  273. A
  274. .B -d
  275. flag argument produces debugging output if
  276. .B awk
  277. was compiled with "DEBUG" defined.
  278. .IP
  279. Scripts may be "compiled" and run later (providing the installer
  280. did what is necessary to make this work).
  281. .NH 2
  282. Defining Variables On The Command Line
  283. .LP
  284. To pass variable values into a script at run time, you may use
  285. .IP
  286. .I variable=value
  287. .LP
  288. (as many as you like) between any "\fB-f \fIscriptname\fR" or
  289. .I program
  290. and the names of any files to be processed.  For example,
  291. .DS
  292. awk -f awkscript today=\e"`date`\e" infile
  293. .DE
  294. would establish for
  295. .I awkscript
  296. a variable named
  297. .B today
  298. that had as its value the output of the
  299. .B date
  300. command.
  301. .LP
  302. There are a number of caveats:
  303. .IP
  304. Such assignments may appear only between
  305. .B -f
  306. .I awkscript
  307. (or \fIprogram\fR or [see below] \fB-R\fIawk.out\fR)
  308. and the name of any
  309. input file (or '-').
  310. .IP
  311. Each
  312. .I variable=value
  313. combination must be a single argument (i.e. there must not be spaces
  314. around the '=' sign);
  315. .I value
  316. may be either a numeric value or a string.  If it is a string,
  317. it must be enclosed in
  318. double quotes at the time \fBawk\fR reads the argument.  That means
  319. that the double quotes enclosing \fIvalue\fR on the command line
  320. must be protected from the shell as in the example above or it will
  321. remove them.
  322. .IP
  323. .I Variable
  324. is not available for use within the script until after the first record
  325. has been read and parsed, but it is available as soon as
  326. that has occurred so that it may be used before any other
  327. processing begins.  It does not exist at the time the
  328. .B BEGIN
  329. block is executed, and if there was no input it will not exist in the
  330. .B END
  331. block (if any).
  332. .NH 2
  333. Getline Function
  334. .LP
  335. .B Getline
  336. immediately reads the next input line (which is parsed into \fI$1\fR,
  337. \fI$2\fR, etc) and starts processing it at the location of the call
  338. (as opposed to
  339. .B next
  340. which immediately reads the next input line but starts processing
  341. from the start of the script).
  342. .LP
  343. .B Getline
  344. facilitates performing some types of tasks such as
  345. processing files with multiline records and merging
  346. information from several files.  To use the latter as an example,
  347. consider a case where two files, whose lines do not share
  348. a common format, must be processed together.  Shell and \fBawk\fR
  349. scripts to do this might look something like
  350. .sp
  351. In the shell script
  352. .DS
  353. ( echo DATA1; cat datafile1; echo ENDdata1 \e
  354.   echo DATA2; cat datafile2; echo ENDdata2 \e
  355. ) | \e
  356.     awk -f awkscript - > awk_output_file
  357. .DE
  358. In the
  359. .B awk
  360. script
  361. .DS
  362. /^DATA1/  {       # Next input line starts datafile1
  363.           while (getline && $1 !~ /^ENDdata1$/)
  364.                  {
  365.                  [processing for \fIdata1\fR lines]
  366.                  }
  367.           }
  368. .sp 1
  369. /^DATA2/  {       # Next input line starts datafile2
  370.           while (getline && $1 !~ /^ENDdata2$/)
  371.                  {
  372.                  [processing for \fIdata2\fR lines]
  373.                  }
  374.           }
  375. .DE
  376. There are, of course, other ways of accomplishing this particular task
  377. (primarily using \fBsed\fR to preprocess the information),
  378. but they are generally more difficult to write and more
  379. subject to logic errors.  Many cases arising in practice
  380. are significantly more difficult, if not impossible, to handle
  381. without \fBgetline\fR.
  382. .NH 2
  383. Regular Expressions
  384. .LP
  385. The sequence "\fI\eddd\fR" (where 'd' is a digit)
  386. may be used to include explicit octal
  387. values in regular expressions.  This is often useful if "nonprinting"
  388. characters have been used as "markers" in a file.  It has not been
  389. tested for ASCII values outside the range 01 through 0127.
  390. .NH 2
  391. Debugging output
  392. .LP
  393. [This is unlikely to be of interest to the casual user.]
  394. .sp
  395. If \fBawk\fR was compiled with "DEBUG" defined, then giving it a
  396. .B -d
  397. flag argument will cause it to produce debugging output when it is run.
  398. This is sometimes useful in finding obscure problems in scripts, though
  399. it is primarily intended for tracking down problems with \fBawk\fR itself.
  400. .NH 2
  401. Script "Compilation"
  402. .LP
  403. [It is likely that this does not work at most sites.  If it does not, the
  404. following will probably not be of interest to the casual user.]
  405. .sp
  406. The command
  407. .DS
  408. awk -S -f script.awk
  409. .DE
  410. produces a file named
  411. .B awk.out.
  412. This is a core image of
  413. .B awk
  414. after parsing the file
  415. .I script.awk.
  416. The command
  417. .DS
  418. awk -Rawk.out datafile
  419. .DE
  420. causes
  421. .B awk.out
  422. to be applied to \fIdatafile\fR (or the standard input if no
  423. input file is given).  This avoids having to reparse large
  424. scripts each time they are used.  Unfortunately, the way this
  425. is implemented requires some special action on the part of the
  426. person installing \fBawk\fR.
  427. .LP
  428. As \fBawk\fR is delivered with \fI4.2 BSD\fR (and \fI4.3 BSD\fR),
  429. .I awk.out
  430. is created by the \fBawk -S ...\fR process by calling
  431. .B sbrk()
  432. with '0', writing out the returned value, then
  433. writing out the core image from location 0 to
  434. the returned address.  The \fBawk -R...\fR process
  435. reads the first word of
  436. .I awk.out
  437. to get the length of the image, calls
  438. .B brk()
  439. with that length, and
  440. then reads the image into itself starting at location 0.
  441. For this to work, \fBawk\fR must have been loaded with its
  442. text segment writeable.  Unfortunately,
  443. the \fIBSD\fR default for \fBld\fR is to load with the text
  444. read-only and shareable.  Thus, the installer must remember to take
  445. special action (e.g. "cc -N ..."
  446. [equivalently "ld -N ..."] for \fI4BSD\fR) if these
  447. flags are to work.
  448. .LP
  449. [Personally, I don't think it is
  450. a very good idea to give \fBawk\fR the opportunity
  451. to write on its text segment; I changed it so that
  452. only the data segment is overwritten.]
  453. .LP
  454. Also, due to what appears to be a lapse in logic, the first
  455. non-flag argument following \fB-R\fIawk.out\fR is discarded.
  456. [Disliking that behavior, the I changed it so that the \fB-R\fR flag
  457. is treated like the \fB-f\fR flag:  no flag arguments may follow it.]
  458. # .bp
  459. .NH
  460. Sketchily Documented Features
  461. .LP
  462. .NH 2
  463. Exit
  464. .LP
  465. The user manual says that using the
  466. .B exit
  467. function causes the script to behave as if end-of-input has been reached.
  468. Not menitoned explicitly is the fact that this will cause the
  469. .B END
  470. block to be executed if it exists.
  471. Also, two things are ommitted:
  472. .IP
  473. \fBexit(\fIexpr\fB)\fR causes the script's exit status to be
  474. set to the value of \fIexpr\fR.
  475. .IP
  476. If
  477. .B exit
  478. is called within the
  479. .B END
  480. block, the script exits immediately.
  481. .NH 2
  482. Mathematical Functions
  483. .LP
  484. The following builtin functions exist and are mentioned in
  485. .I awk(1)
  486. but not in the user manual.
  487. .IP \fBint(\fIx\fB)\fR 10
  488. \fIx\fR trunctated to an integer.
  489. .IP \fBsqrt(\fIx\fB)\fR 10
  490. the square root of \fIx\fR for \fIx\fR >= 0, otherwise zero.
  491. .IP \fBexp(\fIx\fB)\fR 10
  492. \fBe\fR-to-the-\fIx\fR for -88 <= \fIx\fR <= 88, zero
  493. for \fIx\fR < -88, and dumps core for \fIx\fR > 88.
  494. .IP \fBlog(\fIx\fB)\fR 10
  495. the natural log of \fIx\fR.
  496. .NH 2
  497. OFMT Variable
  498. .LP
  499. The variable
  500. .B OFMT
  501. may be set to, e.g. "%.2f", and purely numerical output will be
  502. bound by that restriction in
  503. .B print
  504. statements.  The default value is "%.6g".  Again, this is mentioned in
  505. .I awk(1)
  506. but not in the user manual.
  507. .NH 2
  508. Array Elements
  509. .LP
  510. The user manual states that "Array elements ... spring into existence by
  511. being mentioned."  This is literally true;
  512. .I any
  513. reference to an array element causes it to exist.
  514. ("I was thought about, therefore I am.")
  515. Take, for example,
  516. .DS
  517. if(array[$1] == "blah")
  518.     {
  519.     [process blah lines]
  520.     }
  521. .DE
  522. If there is not an existing element of
  523. .B array
  524. whose subscript is the same as the contents of the
  525. current line's first field,
  526. .I
  527. one is created
  528. .R
  529. and its value (null, of course) is then compared
  530. with "blah".  This can be a bit
  531. disconcerting, particularly when later processing is using
  532. .DS
  533. for (i in \fBarray\fR)
  534.         {
  535.         [do something with result of processing
  536.     "blah" lines]
  537.         }
  538. .DE
  539. to walk the array and expects all the elements to be non-null.
  540. Succinct practical examples are difficult to construct, but
  541. when this happens in a 500 line
  542. script it can be difficult to determine what has gone wrong.
  543. .NH 2
  544. FS and Input Fields
  545. .LP
  546. By default any number of spaces or tabs can separate fields (i.e.
  547. there are no null input fields) and trailing spaces and tabs
  548. are ignored.  However, if
  549. .B FS
  550. is explicitly set to any character other than a space
  551. (e.g., a tab: \fBFS = "\et"\fR), then a field is defined
  552. by each such character and trailing field separator characters are
  553. not ignored.  For example, if '>' represents a tab then
  554. .DS
  555. one>>three>>five>
  556. .DE
  557. defines six fields, with fields two, four, and six being empty.
  558. .LP
  559. If
  560. .B FS
  561. is explicitly set to a space (\fBFS\fR = "\ "), then
  562. the default behavior obtains (this may be a bug); that
  563. is, both spaces
  564. and tabs are taken as field separators, there can be no
  565. null input fields, and trailing spaces and tabs are ignored.
  566. .NH 2
  567. RS and Input Records
  568. .LP
  569. If
  570. .B RS
  571. is explicitly set to the null string (\fBRS\fR = ""), then the input
  572. record separator becomes a blank line, and the newlines at the end
  573. of input lines is a field separator.  This facilitates
  574. handling multiline records.
  575. .NH 2
  576. "Fall Through"
  577. .LP
  578. This is mentioned in the user manual, but it is important
  579. enough that it is worth pointing out here, also.
  580. .LP
  581. In the script
  582. .DS
  583. /\fIpattern_1\fR/  {
  584.              [do something]
  585.              }
  586. .sp
  587. /\fIpattern_2\fR/  {
  588.              [do something]
  589.              }
  590. .DE
  591. all input lines will be compared with both 
  592. .I pattern_1
  593. and
  594. .I pattern_2
  595. unless the
  596. .B next
  597. function is used before the closing '}' in the
  598. .I pattern_1
  599. portion.
  600. .NH 2
  601. Output Redirection
  602. .LP
  603. Once a file (or pipe) is opened by
  604. .B awk
  605. it is not closed until
  606. .B awk
  607. exits.  This can occassionally cause problems.  For example,
  608. it means that a script that sorts its input lines into
  609. output files named by the contents of their first fields
  610. (similar to an example in the user manual)
  611. .DS
  612. { print $0 > $1 }
  613. .DE
  614. is going to fail if the number of different first fields exceeds
  615. about 10.
  616. This problem
  617. .I cannot
  618. be avoided by using something like
  619. .DS
  620. {
  621. command = "cat >> " $1
  622. print $0 | command
  623. }
  624. .DE
  625. as the value of the variable
  626. .B command
  627. is different for each different value of
  628. .I $1
  629. and is therefore treated as a different output "file".
  630. .LP
  631. [I have not been able to create a truly satisfactory
  632. fix for this that doesn't involve having \fBawk\fR treat output
  633. redirection to pipes differently from output to files; I
  634. would greatly appreciate hearing of one.]
  635. .NH 2
  636. Field and Variable Types, Values, and Comparisons
  637. .LP
  638. The following is a synopsis of notes included with \fBawk\fR's
  639. source code.
  640. .NH 3
  641. Types
  642. .LP
  643. Variables and fields can be strings or numbers or both.
  644. .NH 4
  645. Variable Types
  646. .LP
  647. When a variable is set by the assignment
  648. .DS
  649. \fIvar\fR = \fIexpr\fR
  650. .DE
  651. its type is set to the type of
  652. .I expr
  653. (this includes +=, ++, etc). An arithmetic
  654. expression is of type
  655. .I number,
  656. a concatenation is of type
  657. .I string,
  658. etc.
  659. If the assignment is a simple copy, e.g.
  660. .DS
  661. \fIvar1\fR = \fIvar2\fR
  662. .DE
  663. then the type of
  664. .I var1
  665. becomes that of
  666. .I var2.
  667. .LP
  668. Type is determined by context; rarely, but always very inconveniently,
  669. this context-determined type is incorrect.  As mentioned in
  670. .I awk(1)
  671. the type of an expression can be coerced to that desired.  E.g.
  672. .DS
  673. {
  674. \fIexpr1\fR + 0
  675. .sp 1
  676. \fIexpr2\fR ""    # Concatenate with a null string
  677. }
  678. .DE
  679. coerces
  680. .I expr1
  681. to numeric type and
  682. .I expr2
  683. to string type.
  684. .NH 4
  685. Field Types
  686. .LP
  687. As with variables, the type of a field is determined by
  688. context when possible, e.g.
  689. .RS
  690. .IP $1++ 8
  691. clearly implies that \fI$1\fR is to be numeric, and
  692. .IP $1\ =\ $1\ ","\ $2 16
  693. implies that $1 and $2 are both to be strings.
  694. .RE
  695. .LP
  696. Coercion is done as needed.
  697. In contexts where types cannot be reliably determined, e.g.,
  698. .DS
  699. if($1 == $2) ...
  700. .DE
  701. the type of each field is determined on input by inspection.  All fields are
  702. strings; in addition, each field that contains only a number
  703. is also considered numeric.  Thus, the test
  704. .DS
  705. if($1 == $2) ...
  706. .DE
  707. will succeed on the inputs
  708. .DS
  709. 0       0.0
  710. 100     1e2
  711. +100    100
  712. 1e-3    1e-3
  713. .DE
  714. and fail on the inputs
  715. .DS
  716. (null)      0
  717. (null)      0.0
  718. 2E-518      6E-427
  719. .DE
  720. "only a number" in this case means matching the regular expression
  721. .DS
  722. ^[+-]?[0-9]*\e.?[0-9]+(e[+-]?[0-9]+)?$
  723. .DE
  724. .NH 3
  725. Values
  726. .LP
  727. Uninitialized variables have the numeric value 0 and the string value "".
  728. Therefore, if \fIx\fR is uninitialized,
  729. .DS
  730. if(x) ...
  731. if (x == "0") ...
  732. .DE
  733. are false, and
  734. .DS
  735. if(!x) ...
  736. if(x == 0) ...
  737. if(x == "") ...
  738. .DE
  739. are true.
  740. .LP
  741. Fields which are explicitly null have the string value "", and are not numeric.
  742. Non-existent fields (i.e., fields past \fBNF\fR) are also treated this way.
  743. .NH 3
  744. Types of Comparisons
  745. .LP
  746. If both operands are numeric, the comparison is made
  747. numerically.  Otherwise, operands are coerced to type
  748. string if necessary, and the comparison is made on strings.
  749. .NH 3
  750. Array Elements
  751. .LP
  752. Array elements created by
  753. .B split
  754. are treated in the same way as fields.
  755. ----------------------------------------------------------------------------
  756. Francois-Michel Lang
  757. Paoli Research Center, Unisys         lang@prc.unisys.com      (215) 648-7256
  758. Dept of Comp & Info Science, U of PA  lang@linc.cis.upenn.edu  (215) 898-9511
  759.  
  760.  
  761.