LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-17-2006, 09:31 AM   #1
Joe Marrero
LQ Newbie
 
Registered: May 2006
Posts: 2

Rep: Reputation: 0
Weird behavior with exported shell variable


Hi. I am having trouble trying to figure out why the following script does not work. It seems to be a variable scope issue but I don't know why the inner while loop can see the outer variable 'cpuinfo_output' but the rest of the script doesn't see the changes. I even exported the variable thinking that maybe the while loop was creating a sub shell. Please if anyone could help me, I would really appreciate it. Thanks.

Code:
#!/bin/bash

cpuinfo=`grep -e processor -e "model name" -e "cache size" /proc/cpuinfo -h | sed 's/^.*: //'`


export cpuinfo_output=""
echo "parent pid = $$"

echo "$cpuinfo" > /tmp/.heartbeat.tmp
cat /tmp/.heartbeat.tmp | (
while read i 
do 
	echo "pid = $$"
	cpuinfo_output="${cpuinfo_output}:${i}"
	echo "${cpuinfo_output}"
	export cpuinfo_output
done
)

rm /tmp/.heartbeat.tmp
echo "--> '$cpuinfo_output'"
 
Old 12-17-2006, 09:43 AM   #2
Joe Marrero
LQ Newbie
 
Registered: May 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Solved.

Nevermind. Its solved. The solution was to change to this:


exec 3<> /tmp/.heartbeat.tmp
while read i <&3
do
echo "pid = $$"
cpuinfo_output="${cpuinfo_output}:${i}"
echo "${cpuinfo_output}"
export cpuinfo_output
done
exec 3>&-
 
  


Reply


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
Is it possible to locate where an environmental variable is exported from? laggerific Linux - Software 2 12-07-2006 12:55 PM
Weird behavior!! surfer41 Linux - Networking 1 04-25-2006 07:53 AM
Weird behavior Bassy Linux - Software 2 10-20-2005 01:32 PM
weird mount behavior sohmc Linux - Hardware 0 06-07-2005 07:06 AM
Weird Knode behavior PapaNoHair Mandriva 0 11-09-2003 06:39 PM


All times are GMT -5. The time now is 10:15 AM.

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