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
Wrap
Text File
|
1995-05-21
|
2KB
|
68 lines
Syntax: strcmp <opts> string1 op string2 <opts>
Function: Carry out requested comparison
Options:
-c ignore case for comparison
-d debug mode
-p write reply to stdout
-s suppress displays
Op codes:
eq equal
lt less than
gt greater than
le less or equal to
ge greater or equal to
ne not equal
ct contains
bw begins with
Result: (returned as result code)
0 test was TRUE
1 test was FALSE
4 parameter errors found
The case of option codes and operators is ignored.
Strcmp was originally written to provide additional string comparison
facilities for Sculptor programs, which at version 1:14.5 could not do
caseless comparisons. It follows Unix shell conventions about TRUE/FALSE
replies and so can be used with any shell whose scripts provide conditional
processing. Strcmp has the sticky bit set so it can be used in loops without
undue performance overheads.
Typical use is:
if strcmp -c $name ct foo
then
echo $name contains Foo (found by a caseless comparison)
else
echo $name is foo-less
fi
Comparison strings should be enclosed in double quotes if they contain spaces
and in single quotes if they contain words which the shell might interpret.
The -d and -p options can be used to help debug your scripts. The -s option
is for use where the parameters may cause errors in strcmp that you want to
handle solely via the error reply. It is there to prevent error displays
generated by strcmp from corrupting Sculptor forms displays:
i1 input op
cmd = 'strcmp -cs "'+fname+'" '+op+' "'+tname+'"'
exec cmd
if tstat = 4 then\
error "Invalid comparison type supplied":\
goto i1
if tstat = 0 then message "Comparison succeeded"
if tstat = 1 then message "Comparison failed"
Apologies to non-Sculptor freaks, but you should still get the gist of the
above.
The lt, gt, le and ge operators have their conventional argument orderings:
"aaa lt aab" is TRUE. The ct and bw operators look for the second string as
a substring within the first string.
Strcmp always expects three arguments in the specified order. Extra arguments
are ignored. As a result its error messages may sometimes be misleading if you
don't read them in this light, especially if the first string is unquoted and
contains spaces.