Hi.
Make you feel at home:
Code:
#!/usr/bin/env rexx
/*
# @(#) s1 Demonstrate Linux rexx.
*/
subject = 'We are looking for an item in a line.'
If WORDPOS('item', subject) > 0 Then
SAY 'Found it.'
Else
SAY ' Cannot see item.'
exit 0
Producing:
Code:
% ./s1
Found it.
Make me feel at home:
Code:
#!/bin/bash -
# @(#) s1 Demonstrate rexx function emulation.
debug="echo"
debug=":"
wordpos() {
local phrase="$1" string="$2"
$debug " wordpos, looking for $phrase in $string"
if [[ $string == *$phrase* ]]
then
return 0
else
return 1
fi
}
if wordpos item "Jack and Jill"
then
echo " Found it (unexpected!)."
fi
if wordpos item "Now here is an item embedded."
then
echo " Found it (expected)."
fi
exit 0
Producing:
Code:
% ./s2
Found it (expected).
The key to s2 is not the function, of course, it is the syntax of and in the if statement. The page at http://www.tldp.org/LDP/abs/html/index.html is long, but valuable... cheers, drl
|