Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
typeset -p output gives shows variables which can't be read back in
- X-seq: zsh-workers 28803
- From: Rocky Bernstein <rocky@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: typeset -p output gives shows variables which can't be read back in
- Date: Sun, 27 Feb 2011 06:44:30 -0500
- 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=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Sender: rocky.bernstein@xxxxxxxxx
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author