Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 03-02-2012, 04:09 PM   #16
Senior Member
Registered: Nov 2005
Distribution: Debian
Posts: 2,498

Rep: Reputation: 853Reputation: 853Reputation: 853Reputation: 853Reputation: 853Reputation: 853Reputation: 853

export passes variables to subprocesses, but that doesn't help getting the data back to the parent:
$ export x=fish
$ echo $x
$ whoami | while :;do x=chips;break;done
$ echo $x
The problem is explained in detail here: I set variables in a loop that's in a pipeline. Why do they disappear after the loop terminates? Or, why can't I pipe data to read?

Last edited by ntubski; 03-02-2012 at 04:10 PM. Reason: used [quote] instead of [code]
Old 07-30-2014, 01:12 PM   #17
LQ Newbie
Registered: Mar 2013
Posts: 1

Rep: Reputation: Disabled
Another way to fix the problem is to place the input into a file,
then redirection to have the while loop process the file


Doesn't work due to pipe causing subprocess being created:
export conflict=0
cat $filename | while read inline

echo $conflict # get 0

export conflict=0
while read inline
done < $filename

echo $conflict # get 1 !

Since no pipe, no subprocess created, values in while loop retained


bash, loop, management, package, variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Define global variable maxmil Linux - Newbie 4 03-07-2006 10:36 AM
How can I define a global variable? kloss Linux - General 4 02-21-2006 04:30 AM
diff between #define and const defined variable b123coder Programming 7 06-27-2005 08:02 AM
how am i define an environment variable? yenonn Slackware 2 12-19-2003 07:44 AM
how to define a global variable Anniebaby Programming 1 11-09-2003 10:43 PM

All times are GMT -5. The time now is 05:17 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration