![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading variable from file variable values | sagii | Shell Programming and Scripting | 5 | 06-27-2009 01:06 PM |
| Not access variable outside loop when a reading a file | ricardo.ludwig | Shell Programming and Scripting | 4 | 05-23-2009 11:14 PM |
| reading more than one variable into a for loop | starsky | UNIX for Dummies Questions & Answers | 3 | 10-24-2008 12:01 PM |
| How to make a loop base on reading a file? | JohnBalayo | UNIX for Dummies Questions & Answers | 3 | 04-02-2008 06:36 AM |
| How to make a loop base on reading a file? | JohnBalayo | HP-UX | 3 | 04-01-2008 11:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to get the modified value of variable outside the while loop reading from a file
Hi Friends ,
Sorry if this is a repeated question , Quote:
i=5; count=15 but the variables are not updating , the value of variables showing i=0 and count =0 only. ![]() can any1 help me please. |
|
||||
|
Updated code below..
Code:
count=0 i=0 while read line do i=`expr "$i" + 1` count=`expr "$count" + "$i"` done < input.txt echo " i Value =$i " echo " Count Value = $count" Code:
i Value =5 Count Value = 15 |
|
||||
|
Code:
> cat temp.bash count=0 i=0 while read line do i=`expr "$i" + 1` count=`expr "$count" + "$i"` done < input.txt echo " i Value =$i " echo " Count Value = $count" > bash temp.bash i Value =5 Count Value = 15 Note : Did you given the variables with in double quote, Pls check |
|
||||
|
hii Palse,
sorry the variable values are not updating , let me post the code which i have written ( as u said) Code:
#!/bin/bash count=0 i=0 while read line do i=`expr "$i" + 1` count=`expr "$count" + "$i"` done < input.txt echo " i value = $i"; echo " count value = $count"; -bash-3.00$ sh readLine.sh i value = 0 count value = 0 What do u say ? Last edited by babusek; 07-20-2009 at 07:17 AM.. Reason: code tags, PLEASE! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|