From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2930 invoked by alias); 28 Feb 2011 07:09:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28810 Received: (qmail 21896 invoked from network); 28 Feb 2011 07:09:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110227230923.ZM5385@torch.brasslantern.com> Date: Sun, 27 Feb 2011 23:09:23 -0800 In-reply-to: Comments: In reply to Rocky Bernstein "Re: typeset -p output gives shows variables which can't be read back in" (Feb 28, 12:08am) References: <110227130132.ZM4792@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: typeset -p output gives shows variables which can't be read back in MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 28, 12:08am, Rocky Bernstein wrote: } } As for the typeset -T and typeset -p not showing -T associations, I think } that's a misfeature. } } Should I look into providing a patch for this? I think first there needs to be a bit of discussion about what the result should look like. E.g. if I have typeset -T SCALAR=x:y:z array and then I do typeset -p SCALAR typeset -p array should I get the exact same output both times? Also what should the value of $parameters[foo] look like? My first idea is something like array-tied:FOO but there may be problems with that which I haven't foreseen. } Saving an environment for reloading into another session, whether } nested or not, might be useful in other contexts. Possibly the code } you or I have in zshdb could be turned into a function and put inside } the parameter module? Until you mentioned the debugger, I was completely at a loss to come up with an environment where you'd want to attempt to reload any parameter that is normally maintained by the shell internals (such as any of the variables in the $parameter module, or most of the other modules for that matter). I still can't think of one. However, parameters that are marked "typeset -H" and thus have their values suppressed in the typeset -p output can only be saved/restored by tricks that would be better applied in a C function, so I can't really argue against it. } What I'm thinking of now is adding a function save_var which takes the } name of a variable one wants to persist. That makes a bit more sense, but in that case you have a list of the names and can do for param in "${save_vars[@]}" do case $parameters[$param] in (*assoc*) print -- "typeset -A $param; $param=( ${(P@kvqq)param} )";; (*array*) print -- "typeset -a $param; $param=( ${(P@qq)param} )";; # etc. done > $the_save_file The point being that one doesn't need to dump the entire output of typeset, only the parameters whose names are explicitly known. } If there is something like a tie function like there is in Perl or a } discipline function on a varaible like ksh, that might be used, but } this would be on a per-variable basis. There's not, at this time. } On Sun, Feb 27, 2011 at 4:01 PM, Bart Schaefer wrote: } > } > () { } > local param type } > for param type in "${(kv@)parameters}" } > do } > case "$type" in } > (*local*) continue;; # Skip loop variables } > (*export*) continue;; # No need to dump/restore if exported? } > (*special*) continue;; # Maintained by the shell } > (*readonly*) continue;; } > (*) typeset -p "$param";; } > esac } > done } > } } } But while we are being precise, let me point out that it is wrong to } say that a local variable is a "loop" variable as you suggest in the } code above. I was referring to skipping "param" and "type", the variables for the loop over ${(kv)parameters}. There aren't any other locals in the anonymous scope (though there could be in a surrounding scope).