From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28991 invoked by alias); 27 Feb 2011 12:36:44 -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: 28803 Received: (qmail 4366 invoked from network); 27 Feb 2011 12:36:42 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.213.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:date:x-google-sender-auth :message-id:subject:from:to:content-type; bh=w7P3ArsMxg27poiZdGK0i994T6K0FlNhNlFXRFRzAFc=; b=Yw/HwgtxhUGXwTyD6Ikgr9k7cpxwuetO51h4XzDsH64PTV3RFoB6XzFYZwA77wxGqp 0klrCU0uNOJQOL1ynBabom5+D2Y6epv9FPcH4dTNyU3lvHTHxJA4JynSQRrJmd+JXXQn cT521jlssVcjqAQ9aoDFxkPD65x2TaJqkJ8V4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=cIPRONGXZkdhkjKLl2W/Q3jRIa3zsfVYNXVYtszdUhatVsE0elVIG4bN6YLX2gOfEo AK6IZe/cLmJ3jlVQ/iWbHfGiGbeVcfDL+/aH+N0zdN7XDNH3TOjOX7R1J2hNEKbFs1hi PvvN0537J81Lo3TGm+UJKECqupY7YAfQhG2gw= MIME-Version: 1.0 Sender: rocky.bernstein@gmail.com Date: Sun, 27 Feb 2011 06:44:30 -0500 X-Google-Sender-Auth: r7mVHhPN0N-NMPUzLMENngv0eLY Message-ID: Subject: typeset -p output gives shows variables which can't be read back in From: Rocky Bernstein To: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary=000e0cd719e4101baf049d421645 --000e0cd719e4101baf049d421645 Content-Type: text/plain; charset=ISO-8859-1 I would like to save to a file shell variables so that I can run a nested zsh and then read these back in. It is becoming a bit of a challenge because this in the output: typeset -i10 -r !=0 typeset -i10 -r '#'=0 typeset -i10 -r '$'=15221 typeset -ar '*' *=() typeset -r -=569Xfy typeset 0=_Dbg_do_shell typeset -i10 -r '?'=0 typeset -ar @ @=() typeset -rx _=-p Failing a better solution, I think what I'll have to do is store IFS='' typeset -p into an array and check each item of the array. But even this is turning out to be a bit challenging. One thing that one needs to do is look for read-only variables and then I guess turn that into a test followed by the typeset. That is typeset -p ARGC 2>/dev/null 1>/&2 && typeset -i10- r ARGC=0 Next one needs to check that the types valid which would weed out the lines above. But then we come to the typeset -ar '*' line which I guess flows onto the next line. At first I thought I could remove any lines that don't start with "typeset", but this is wrong because I could have a line like: typeset ZSH_DEBUG_CMD='if [ -d /etc/profile.d ] then for i in /etc/profile.d/*.sh do if [ -r $i ] then . $i fi done unset i fi' and all of that will read back in fine. Any suggestions? A little bit of context of why I am doing this. Recently in the zsh debugger I've added the ability to go into a nested zsh, and often one wants the existing environment of the debugged program preserved in this nested zsh. Lastly, related on a different topic. I notice there's no option for sourcing a startup file by name. Instead the closest thing is to create a temporary directory and in that create a file called .zshenv and set ZDOTDIR. This works, but strikes me as a bit awkward and more convoluted than adding an option to indicated an additional profile to run. Many POSIX-like shell languages, notably ksh don't provide such an option, bash does and it is called --init-file. And "higher-level" scripting languages which have modules like Perl, Python, or Ruby all do as well. --000e0cd719e4101baf049d421645--