[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: namref dicussion continued: [PATCH] export -r reference

From: Piotr Grzybowski
Subject: Re: namref dicussion continued: [PATCH] export -r reference
Date: Thu, 5 May 2016 09:46:46 +0200

 ok, so Dan wants this patch.
 I took a look at your script, there are two cases it addresses: exporting 
nameref and doing it from inside the function scope, I applied both patches:

nameref masking in scope:

exporting namerefs:

and with this modification to your script:

diff --git a/exportscope b/exportscope
index 05bae73..0125681 100644
--- a/exportscope
+++ b/exportscope
@@ -37,7 +37,8 @@ function h {
                        typeset -n _x=$2
-                       typeset -x _x='in h2'
+                       export -r _x;
+                       _x='in h2';
                        eval "$showEnv" h2
@@ -75,4 +76,4 @@ for sh in bash ksh mksh zsh; do
        printf '%s\n\n' "$("$sh" -c "$code" -- "$sh" 2>&1)"

You can get (difference in test 3):

bash test 1:
    subprocess f: declare -x x="in f"
    local f: declare -x x="in f"
    global: declare -x x="global"
bash test 2:
    subprocess g: declare -x x="in g"
    subprocess f: declare -x x="in f"
    local f: declare -x x="in f"
    local g: declare -x x="in g"
    global: declare -- x="unset"
bash test 3:
    subprocess h2: declare -x x="in h2"
    subprocess h1: declare -x x="in h2"
    local h1: declare -x x="in h2"

 Maybe you can comment on wether the patches are valid.


On 4 May 2016, at 22:40, Dan Douglas wrote:

> Yeah I was just looking for this old script last night and just found it :)
> https://gist.github.com/ormaaj/04923e11e8bdc27688ad
> If you scroll down to the output for "test 3" where "h" gets called
> and passes a local "x" to a function that creates a reference to it
> and exports the reference you can see that bash calls "x" unset in
> both the first and second scope. As I recall we were discussing the
> way exported locals interact between scopes at the time, not namerefs,
> but I added the case for namerefs since I wasn't sure how this should
> work. I should probably run it again with the current devel branch.
> Even though bash doesn't yet support references for parameters like
> ksh93, neither does mksh, which also shows differences from bash.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]