On Mon, 2 Dec 2013, Matteo Cavalleri wrote:
> after reading the documentation and looking for examples i’m still 
> having some issues with variable scoping, i.e. i’m trying to make some 
> variables local to the whole script, not just a function, and of course 
> i’d like to avoid leaking them to the calling shell.
> 
> i’ve seen i can define functions inside a function, but it seems is not 
> possibile to have variables defined in the “top” function available in 
> the sub functions as well. i’ve tried with “set”, “set -lx”, “set -x”, 
> “set -gu” etc with no avail. i know i can pass arguments to functions, 
> but before ending up passing the same 5 or 6 variables to every function 
> call, i wanted to see if there’s a way to have script-scoped variables.

I think you want --no-scope-shadowing on the sub functions. It is not 
terribly well explained in the documentation; I struggled to get my head 
around it a bit the first time.

With

```
function echosomething
    echo $something
end

function showsomething
    set something 1
    echosomething
end
```

> showsomething
<blank output>
> echo $something
<blank output>
> B

However, with

```
function echosomething --no-scope-shadowing
    echo $something
end
```

> showsomething
1
> echo $something
<blank output
> 

HTH,

David Adam
zanc...@ucc.gu.uwa.edu.au
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to