home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / SHELLS / sh73.lzh / DOC / strcmp.doc < prev   
Text File  |  1995-05-21  |  2KB  |  68 lines

  1. Syntax:   strcmp <opts> string1 op string2 <opts>
  2. Function: Carry out requested comparison
  3. Options:
  4.           -c    ignore case for comparison
  5.           -d    debug mode
  6.           -p    write reply to stdout
  7.           -s    suppress displays
  8. Op codes:
  9.           eq    equal
  10.           lt    less than
  11.           gt    greater than
  12.           le    less or equal to
  13.           ge    greater or equal to
  14.           ne    not equal
  15.           ct    contains
  16.           bw    begins with
  17. Result: (returned as result code)
  18.           0     test was TRUE
  19.           1     test was FALSE
  20.           4     parameter errors found
  21.  
  22. The case of option codes and operators is ignored.
  23.  
  24. Strcmp was originally written to provide additional string comparison 
  25. facilities for Sculptor programs, which at version 1:14.5 could not do 
  26. caseless comparisons. It follows Unix shell conventions about TRUE/FALSE
  27. replies and so can be used with any shell whose scripts provide conditional
  28. processing. Strcmp has the sticky bit set so it can be used in loops without
  29. undue performance overheads.
  30.  
  31. Typical use is:
  32.  
  33.     if strcmp -c $name ct foo
  34.     then
  35.         echo $name contains Foo (found by a caseless comparison)
  36.     else
  37.         echo $name is foo-less
  38.     fi
  39.  
  40. Comparison strings should be enclosed in double quotes if they contain spaces
  41. and in single quotes if they contain words which the shell might interpret.
  42.  
  43. The -d and -p options can be used to help debug your scripts. The -s option
  44. is for use where the parameters may cause errors in strcmp that you want to
  45. handle solely via the error reply. It is there to prevent error displays 
  46. generated by strcmp from corrupting Sculptor forms displays:
  47.  
  48. i1    input op
  49.     cmd = 'strcmp -cs "'+fname+'" '+op+' "'+tname+'"'
  50.     exec cmd
  51.     if tstat = 4 then\ 
  52.         error "Invalid comparison type supplied":\
  53.         goto i1
  54.     if tstat = 0 then message "Comparison succeeded"
  55.     if tstat = 1 then message "Comparison failed"
  56.  
  57. Apologies to non-Sculptor freaks, but you should still get the gist of the 
  58. above.
  59.  
  60. The lt, gt, le and ge operators have their conventional argument orderings:
  61. "aaa lt aab" is TRUE. The ct and bw operators look for the second string as
  62. a substring within the first string. 
  63.  
  64. Strcmp always expects three arguments in the specified order. Extra arguments 
  65. are ignored. As a result its error messages may sometimes be misleading if you
  66. don't read them in this light, especially if the first string is unquoted and 
  67. contains spaces.
  68.