<html>
<font size=3>Fred,<br>
Generally when you are looping and redirecting input to the loop, either
through a<br>
<br>
while<br>
do<br>
.<br>
.<br>
.<br>
done &lt; some file<br>
<br>
or by piping as you have done here, the loop will run in a subshell which
means any variables which are assigned values within the loop will be
lost when the loop terminates.<br>
<br>
Regards,<br>
krf<br>
<br>
At 09:12 AM 2/27/2002 -0600, you wrote:<br>
<blockquote type=cite cite>(Sorry - on the first attempt I cut out the
discussion part - second try here)<br>
<br>
#! /bin/bash<br>
#<br>
makeList.sh<br>
#<br>
ServerList=$1<br>
WordList=$2<br>
<br>
declare -a S<br>
declare -a U<br>
<br>
Count=0<br>
cat $ServerList | while read Server User<br>
do<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>S[$Count]=$Server<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>U[$Count]=$User<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>Count=`expr
$Count + 1`<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>echo
&quot;$Count&quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>echo
&quot;${#S[*]} ${#S[@]}&quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>ACount=$Count<br>
done<br>
echo &quot;count : $Count&quot;<br>
echo &quot;number of elements : ${#S[*]} ${#S[@]}&quot;<br>
echo &quot;acount : $ACount&quot;<br>
<br>
Leave=0<br>
echo &quot;$Leave $Count&quot;<br>
while test $Leave -lt $Count<br>
do<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>echo
&quot;$Leave: ${S[$Leave]} ${U[$Leave]}&quot;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>Leave=`expr
$Leave + 1`<br>
done<br>
exit<br>
<br>
<br>
<br>
Victor Brilon wrote:<br>
<br>
<blockquote type=cite cite>Can you post some code showing exactly what
you mean? Sounds like<br>
you're running into a variable scope problem maybe.<br>
Victor<br>
On 26-Feb-2002 Fred James wrote:<br>
<br>
<blockquote type=cite cite>Within a while loop, strings are assigned to
the elements of an<br>
array, and the index variable is incremented.<br>
<br>
Once the loop completes, the value of the index variable is zero.<br>
<br>
What is happening?<br>
<br>
-- ...make every program a filter...<br>
<br>
<br>
_______________________________________________<br>
<a href="http://www.ntlug.org/mailman/listinfo/discuss" eudora="autourl">http://www.ntlug.org/mailman/listinfo/discuss</a><br>
</blockquote></blockquote><br>
<br>
-- <br>
...make every program a filter...<br>
<br>
<br>
_______________________________________________<br>
<a href="http://www.ntlug.org/mailman/listinfo/discuss" eudora="autourl">http://www.ntlug.org/mailman/listinfo/discuss</a></font></blockquote></html>