![]() |
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 |
| Not access variable outside loop when a reading a file | ricardo.ludwig | Shell Programming and Scripting | 4 | 05-23-2009 11:14 PM |
| 'while' loop does not change local variables?! | alex_5161 | Shell Programming and Scripting | 3 | 11-20-2008 02:06 PM |
| While loop - The sum seems to be local | eagercyber | Shell Programming and Scripting | 2 | 03-26-2008 04:06 AM |
| Unable to access home area | Mr Pink | SUN Solaris | 1 | 04-15-2007 05:57 PM |
| unable to access hpfs/ntfs properly | moxxx68 | UNIX for Dummies Questions & Answers | 1 | 11-08-2005 04:13 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
unable to access a variable not local to a while loop
I have a while loop like this
cat ${filename} | while read fileline do ... done I need to access a variable value $newfile inside this while loop How will i do that?? |
|
||||
|
You should be able to read any variable that has been set at that point. Assigning to it won't work because the pipe forces the while loop to run in a subshell; assignments will be visible within the while loop but will be lost when the loop is exited. I generally use temporary files to work around this, but sometimes run it in a "eval $(expression)" and have it echo the variable assignment(s) to stdout. (The latter avoids the various issues with temporary files but is rather more confusing to most people.)
|
|
||||
|
Franklin I tried this before as i saw it in some other post of yours but my requirement is different
cat ${filename} | while read fileline do size=`echo $fileline | cut -d "," -f2` value=`echo $fileline | cut -d "," -f3` info=`echo $fileline | cut -d "," -f4` variable=$passedvariable done I need to read each line from the ${filename} and at the same time get the value of $passedvariable which is declared outside while loop inside the while ![]() |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|