|
From: | Steven W. Orr |
Subject: | Re: YAQAGV (Yet Another Question About Global Variables) |
Date: | Tue, 23 Aug 2011 10:06:55 -0400 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.20) Gecko/20110804 Thunderbird/3.1.12 |
On 8/23/2011 9:52 AM, Greg Wooledge wrote:
On Tue, Aug 23, 2011 at 09:42:21AM -0400, Steven W. Orr wrote:Since require is a function, any variables that are declared in a required module which declare global variables using typeset then become local variables to the require function. Then after the modules are loaded, the variables that used to be global are gone.bash 4.2 adds "declare -g" to create global variables from within a function.
Hmm. I'm wondering if a trap might solve my problem. Bash4.2 doesn't help since we're on 4.0.35, but it would have been nice.
Something like... # old code require() { ... source $fn # fn is global } #new code trap { source $fn; } SIGUSER1 require() { # set the trap. Rats! I need to set it to a function. fn=something_I_want kill -USR1 $$ # unset the trap handler } -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net
[Prev in Thread] | Current Thread | [Next in Thread] |