bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ADDENDUM TO LAST MESSAGE


From: Alex Lanstein
Subject: ADDENDUM TO LAST MESSAGE
Date: Sun, 14 Nov 2004 22:28:57 -0500

I apologize, in my last message I didn't give the environment details
I'm running Fedora Core 2 on an AMD 64bit XP 3000+ with 2 gigs of ecc ram.  

root@peter_griffin --- {~/pics} gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)



I don't really understand why this hasnt been fixed or reported yet,
but when I need a for loop inside a whileloop, all the variabled
created or edited inside the for loop are local, not global.  Here is
example code:

count=1
cat temp5 | while read num
do
if [ "$num" -ge "$count" ]; then
echo "$num" "is bigger than" "$count"
count="$num"
echo "$count" "is the new counter"
else
echo "$count" "is already bigger than" "$num"
fi
done
echo "$count" "is the temp counter now"

when im echoing it inside the loop $count is what it should be (5327)
but as soon as it exits, $count is 1 again

However, if ALL I do is edit the 'cat temp5 | while read num' to 'for
num in $( cat temp5 )', it works perfectly, $count gets echoed as 5327
instead of 1.

If a comment does get added to the code, please give Alex Lanstein and
Twans credit for it.

Thanks!
Alex Lanstein




reply via email to

[Prev in Thread] Current Thread [Next in Thread]