[Solved] KSH: Array/If Help

RedHat 5
KSH

I am creating an array, and then using case to go through and count for specific words. Then the count gets stored as an expression.

string='ftp rcp rsh telnet ftp ftp'
set -A myarray $string
FTPCOUNT="0"
for command in ${myarray[*]}
do
case $command in
ftp) FTPCOUNT=`expr $FTPCOUNT +1` ;;
rcp) RCPCOUNT=`expr $RCPCOUNT +1` ;;
esac
done
if (($FTPCOUNT !=0) || ($RCPCOUNT !=0)); then
echo "It works"
fi

So i do all of this, but my "if $FTPCOUNT !=0; then" part fails
dash_bin_ksh: 3: not found

I can echo $FTPCOUNT and get "3" which is correct.

Can someone point me in the right direction?

Does this work in your ksh?

if (( (FTPCOUNT!=0) || (RCPCOUNT!=0) ))

If not, try:

if [ $FTPCOUNT -ne 0 -o $RCPCOUNT -ne 0 ]
1 Like

Thats perfect...thanks!