Help with multiple for loops

All,
I have set up ssh trust between 3 machines. The aim is to connect from machine-A to B and C and clear the txt files in tmp on all 3 machines. And, I have 3 environments and each environment has 2 hosts. So I should be able to run this script on any environment.

Here is the logic:
I want to see if my current hostname is part of any of these 3 sections/environments, if yes, then go into that section only and do stuff. That is clear the txt only for that section and exit out.

But this isnt working as expected. It does the job but after clearing the txt, it moves onto next section/environment instead of exiting out.

I think nested for isnt working as expected or maybe I shouldnt use nested for in the first place! Please let me know if you have any better ideas to make this work.

Here is the script:

##This script will clear the txt in tmp in both local and remote locations
#!/bin/sh

EXTSSSERVERLIST=ext1.test.com,ext2.test.com
APPSSSERVERLIST=app1.test.com,app2.test.com
FAASERVERLIST=faa1.test.com,faa2.test.com

echo "Clearing txt for Test Domain..."
host=$(hostname)
echo $host;

for $(hostname) in $EXTSSSERVERLIST;
        do
                for f in $(echo $EXTSSSERVERLIST | tr "," " ");
                        do
                        ssh $f "rm -rf /tmp/*.txt"
                        done
        done

for $(hostname) in $APPSSSERVERLIST;
        do
                for f in $(echo $APPSSSERVERLIST | tr "," " ");
                        do
                        ssh $f "rm -rf /tmp/*.txt"
                        done
        done

for $(hostname) in $FAASSSERVERLIST;
        do
        for f in $(echo $FAASSSERVERLIST | tr "," " ");
                do
                ssh $f "rm -rf /tmp/*.txt"
                done
        done

To assist other posters:

Which Operating System and Version are you running?
Which Shell have you written the code for?
Is there a link on your computer from /bin/sh to another (non-Bourne) Shell?

It is Redhat linux. and /bin/sh and there is no link to any other shell

Thanks

To test if your hostname is in a list you should use something like this:

if echo $EXTSSSERVERLIST | grep -wq $host
then
                for f in ${EXTSSSERVERLIST//,/ }
                do
                        ssh $f "rm -rf /tmp/*.txt"
                done
fi

Note that a line of the form:

#!/pathname/of/interpreter

has absolutely no effect on a script unless it is the first line in the script.

Thanks to all

Special thanks to chubler. The code worked perfectly. I am trying it out on other hosts now and will also do some extensive testing before I make it more dynamic.

I am planning to make it more dynamic and use this script to do repeated things like clearing cache, files et al on remote hosts.