Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (6) </ 1 2 3 4 5 [6] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Beta testers needed, bash script testing< Next Oldest | Next Newest >
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 31 2008,16:58 QUOTE

Quote (Zucca @ Jan. 31 2008,10:06)
Quote (^thehatsrule^ @ Jan. 30 2008,14:23)
I think that's because $() uses a subshell in order to execute the command substitution... so the variable is lost afterwards.

But I don't have any "$(command)" there.
I read that to set the variable local only you must use local -command.

But if it is really lost somewhere, is there a way to pass it to the outer process?

Well, `` does the same thing as $() or maybe you weren't looking where parsememinfo was being called (in the memfree function)?

It's not local variables that you are looking at right now... it's the child subshell(?) that cannot pass a variable (directly) to a parent - hence my original suggestion.
Back to top
Profile PM 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Jan. 31 2008,17:37 QUOTE

Ok. I think now how I will manage this problem...

--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Feb. 01 2008,01:38 QUOTE

The easiest way to get a variable value out of a command substition is to echo it into a variable.

Say I have a function func that produces a result in variable RES, and I call func via command substitution (hence in a subshell).  I can get RES into ANSWER this way:
Code Sample

func(){
# blah
RES=5
echo $RES
}

ANSWER=$(func)


In long messy scripts, this can be a good way to pass variables out of functions without getting mixed up global variables.  Klaus Knopper does this all the time.

Note anything written to stdout from func will go into ANSWER, not to the terminal.

If you need something in func to go to the terminal and not go into ANSWER, re-direct that line's stdout to /dev/tty
Back to top
Profile PM 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Feb. 04 2008,21:28 QUOTE

New version.

I made it faster by modifying functions.
Those who like to test it will find it from here.

As always, bug reports are welcome. =)


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
28 replies since Jan. 24 2008,16:16 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (6) </ 1 2 3 4 5 [6] >/
reply to topic new topic new poll
Quick Reply: Beta testers needed

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code