The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
looping a array inside inside ssh is not working, pls help reldb Shell Programming and Scripting 5 07-07-2006 11:32 AM
scripting headache... loops & variables StevePace Shell Programming and Scripting 6 02-07-2006 01:18 AM
passing variables to sed inside script Daniel234 Shell Programming and Scripting 5 11-24-2005 06:15 AM
test to see if useradd worked doublejz Shell Programming and Scripting 3 08-27-2005 04:38 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-13-2005
yongho yongho is offline
Registered User
  
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Variables being worked on inside of loops

I have a while read loop that reads values inside of a file and then performs an expr operation on each.

Everything works fine, the way it's supposed to but, once the loop is finished, I can not access the variable that I used inside of the loop (but that variable was created outside of the loop).

In other words...

PHP Code:
#Init var
myVar=0

while read LINE
do
varInLoop=... #This carries an integer
myVar=`expr $myVAR + $varInLoop#Trying to increment the totals
done

echo "myVar:${myVar}" 
The output of that last echo is "myVar:0"
Is this something I'm not allowed to do? I changed the value of the variable I created outside of the loop, from within the loop, but it didn't change after the loop was done, outside.

I tested the loop, and yes, the loop works, the values are there.
Should I just redirect the output to a file and just use the file as my variable?

Last edited by yongho; 06-13-2005 at 11:33 AM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0