Use while loop - output variable

I'm very much a newbie and hence why this is going to be a stupid question.

I'm attempting to create a korn shell script that pulls zone file locations and includes the copy command in the output. What?

getzonedir.ksh

#!/bin/ksh
while read -r domain
do ls */*"$domain" > $dir1
echo "cp $dir1 $dir1-$2"
done < $1

$1 = user1domains.txt

hosangit.com
djzah.com
ourholychurch.com

$2 = usr1bak

RUN: ./getzonedir.ksh user1domains.txt usr1bak

Expected output...
first step would be the domain zone files are found, so stepping through the first it would find primary.dir/db.hosangit.com (this I want to become a variable so I can echo the command needed to backup this zone file for example "cp primary.dir/db.hosangit.com primary.dir/db.hosangit.com-usr1bak

Am I going about this all wrong?

so you just want to spit out the zone files from named in a loop?

#!/bin/ksh
for ZONE in `find /path/to/file(s) -type f`
 do
   echo ${ZONE}
 done

I keep my zone files in /etc/named/views:

$ ksh getzones.ksh
/etc/named/view/mydomain.internal
/etc/named/view/150.168.192.in-addr.arpa
/etc/named/view/mydomain.external

I know this doesn't answer your question exactly, but I think it should help you get to where you are going. There are other ways to achieve the same thing without using 'find' as well.

Thanks for the feedback...

I use ls */*$domain <--which is fed from the .txt file for the domains I'm interested in and it works great so far but I want to output the results (which would be the full path and zone file name) into a variable. I thought you could output the results using a > to variable name but that doesn't seem to work. If I could get the entire path and file name into a variable then I could either print the variable with the commands I want like

print "cp $fullpathandfilenamevar $fullpathandfilenamevar-bak"

or something like that.

Why would you want to print a shell statement -- why not actually run the shell statement?

> does not redirect into variables, > redirects into files. You may have created a bunch of funny-named files doing this, you'd probably better check :wink:

I'm guessing he is just trying to output what would be happening, before he turns it loose. Just guessing, I tend to do the same when trying something new.

Why wouldn't this work for you?

$ cat mydomains.txt
domain1.com
domain2.com
domain3.com


$ cat getzone.ksh
#!/bin/ksh
#
for domain in `cat ${1}`
 do
   zone=`find . -type f -name \*${domain}\* -print`
   echo "cp ${zone} ${zone}-${2}"
 done

$ ksh getzone.ksh mydomains.txt usr1bak
cp ./dir1/db.domain1.com ./dir1/db.domain1.com-usr1bak
cp ./dir1/db.domain2.com ./dir1/db.domain2.com-usr1bak
cp ./dir2/db.domain3.com ./dir2/db.domain3.com-usr1bak

Thank You for the input. Its just like Blackacid said, I like seeing what should happen before I let it loose. Its my lack of confidence during my learning how to script.