zsh-workers
 help / color / mirror / code / Atom feed
* typeset -p output gives shows variables which can't be read back in
@ 2011-02-27 11:44 Rocky Bernstein
  2011-02-27 21:01 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Rocky Bernstein @ 2011-02-27 11:44 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 2027 bytes --]

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-01 15:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-27 11:44 typeset -p output gives shows variables which can't be read back in Rocky Bernstein
2011-02-27 21:01 ` Bart Schaefer
2011-02-28  5:08   ` Rocky Bernstein
2011-02-28  7:09     ` Bart Schaefer
2011-03-01  3:09       ` Rocky Bernstein
2011-03-01  5:59         ` Bart Schaefer
2011-03-01  6:49           ` Rocky Bernstein
2011-03-01 15:15             ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).