Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Do statements 2

Status
Not open for further replies.
Nov 24, 2004
159
GB
Hi Gurus

I am trying to automate a whole process using a script

is it possile to nest do statements

thanks for looking


my script is
Code:
for FILE in `ls *.txt`;
do
FILEN=$FILE | sed 's/.txt//'
for VOL in `cat $FILE`;
do 

/opt/tivoli/tsm/client/ba/bin/dsmadmc -se=server -id=######## -password=${PASS} "select volume_name from volumes where volume_name='$VOL'" >> /tmp/cont/${FILEN}_bfs.txt ;
done
done
 
Yes you can e.g.
for i in 10 20
do
for j in 1 2
do
echo $i $j
done
done
10 1
10 2
20 1
20 2
 
You are piping a variable assignment

[tt]FILEN=$FILE[/tt]

which doesn't generate any output by the way into a sed process. That won't work...

I suspect you want FILEN to contain the filename in variable FILE but without the .txt

This last step can be done with sed, but you also need command substitution.

to generate the filename with sed:

[tt]echo ${FILE}|sed 's/.txt//'[/tt]

another option is to use the basename command

[tt]basename ${FILE} ".txt"[/tt]


now to put the output of a [tt][red]command[/red][/tt] into a variable, use command substitution:

var=`[tt][red]command[/red][/tt]`

or

var=$([tt][red]command[/red][/tt])

Now it's up to you to put two and two together an see where it gets you.


HTH,

p5wizard
 
I think you wanted something like this:
Code:
for FILE in `ls *.txt`; do
  FILEN=`basename $FILE .txt`
  for VOL in `cat $FILE`; do
    /opt/tivoli/tsm/client/ba/bin/dsmadmc -se=server -id=######## -password=${PASS} "select volume_name from volumes where volume_name='$VOL'" >> /tmp/cont/${FILEN}_bfs.txt
  done
done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top