KSH nested loops?

KSH isn't my strong suit but it's what my company has to offer. I've got a script with two nested loops, a FOR and UNTIL, and that works fine. When I add a CASE into the mix I end up getting "Unexpected 'done' at line xx" errors. Any suggestions on this?

for divi in at ce ci cm co de di fl fr jc ks lo mi ma qf ra sm ho da sw;do
typeset -Z3 store

store=1                                                                      
until [[ $store -eq 999 ]];do                                                   
nslookup moxa1.$divi$store.company.com 2> /dev/null | sed -n '4,5p' >> ~/moxas 

if $store = 999 then
	case $divi in
		"at")
		echo "NAME=CE001 CENTRAL ----------; CT=TELNET; IP=1.1.1.1" >> ~/moxas 
			;;
		"ce") 
		echo "NAME=CI001 CINCINNATI ----------; CT=TELNET; IP=1.1.1.1" >> ~/moxas 
			;;
		"ci") 

esac	

((store=store+1))
                                                                                                                                        
done 
done

The CASE statement actually has 18 options but I cut them out here for brevity.

You are missing the "fi" for the "if" statement.

Holy crap that's a boneheaded mistake, thanks. How ever now I'm getting 'fi' unexpected.

Please display your current code.

for divi in at ce ci cm co de di fl fr jc ks lo mi ma qf ra sm ho da sw;do
typeset -Z3 store

store=1                                                                      
until [[ $store -eq 999 ]];do                                                   
nslookup moxa1.$divi$store.kroger.com 2> /dev/null | sed -n '4,5p' >> ~/moxas 

if $store = 999 then
	case $divi in
		"at")
		echo "NAME=CE001 CENTRAL ----------; CT=TELNET; IP=1.1.1.1" >> ~/moxas 
			;;
		"ce") 
		echo "NAME=CI001 CINCINNATI ----------; CT=TELNET; IP=1.1.1.1" >> ~/moxas 
			;;

	esac	
fi
((store=store+1))
                                                                                                                                        
done 
done

Your "if" statement:

if [[ $store = 999 ]] then

Perfect, thank you.

And if store is sometimes null/empty then it's more safety always add " => value is always something.

if [ "$store" = 999 ] ; then# or
if (($store == 999 )) ; then

Actually, both "=" and "==" should be used for string variables.

As "store" is defined as an integer, the best way is:

if [[ ${store} -eq 999 ]] then

In modern versions of ksh, you can use a more C like syntax in many places. For example,

store=998

if [[ $store = 998 ]]                # old way
then
    echo "one match"
fi

((store++))                          # increment store variable

if (( store == 999 ))                # compare numbers
then
    echo "two match"
fi