Is it possible to have a for loop inside another for loop?

Is it possible to have a for loop nested inside another for loop? I am trying to run a script against specific files inside a child directory but I can't seem to find a solution that is clean and affect to do it. Here is what I am trying do. I have 2 gzip files in each of the Target Directories that I need to run a script against. Then after the report is generated by the script I need to move the report from the Output Target back into the Target Directory. I been looking for way to do the inbedding of the for in another for but I don't really seem to find a way that works. Any help would be appreciated. Thx in Advance.

Starting directory=/mnt
Target Directories=/mnt/TASK-WF001 through 200
Output file Directory=/export/home/files/output_files/

#!/bin/sh
#### Function to automate the running of the audit scripts ####
for x in 1 2 3 4 5 6 7 8 9
do
#### Changing directory to child directory where the files are located ####
cd TASK-WF*$x
for f in `ls *gz`
   do
        echo $f
       /scripts/extract $f
       mv /export/home/files/output_files/* .
   done
done

I see one problem. You're changing directory to the target directory at the start of the outer loop but not returning back up afterward so the next time through the loop, you try to go down one more directory level and fail.

Three possible solutions:
1) Add "cd .." before the outer "done".
2) More fool proof as it doesn't depend on all of the directories being on the same level: change the "cd" command to "pushd" and add a "popd" before the outer "done".
3) Less efficient but, IMHO, cleanest: run the contents of the outer loop in a subshell so the working directory is automatically reset:

#!/bin/sh
#### Function to automate the running of the audit scripts ####
for x in 1 2 3 4 5 6 7 8 9
do
(
#### Changing directory to child directory where the files are located ####
cd TASK-WF*$x
for f in `ls *gz`
   do
        echo $f
       /scripts/extract $f
       mv /export/home/files/output_files/* .
   done
)
done

Thx for your help! I was able to get it functioning properly. I actually had a slight hiccup with the extract script that made me think it was the loops. Dang hidden MS word end of line characters. Cleaned all but one out of the file. Hate it when I get changes sent to me in MS Word. LOL

Not only is ls unnecessary, but it will break your script if any of the filenames contains whitespace or other pathological characters. Use filename expansion directly:

for f in *gz

You need to change directory inside a subshell so that it doesn't affect the directory on the next iteration:

#!/bin/sh
#### Function to automate the running of the audit scripts ####
for x in 1 2 3 4 5 6 7 8 9
do
  #### Changing directory to child directory where the files are located ####
  (
    cd TASK-WF*$x
    : whatever
  )
done

---------- Post updated at 01:41 PM ---------- Previous update was at 01:40 PM ----------

Those are not standard commands.

Sorry. I'm use to bash and didn't notice he was using sh.