From: Rocky Bernstein <rocky@gnu.org>
To: zsh-workers@zsh.org
Subject: typeset -p output gives shows variables which can't be read back in
Date: Sun, 27 Feb 2011 06:44:30 -0500 [thread overview]
Message-ID: <AANLkTimGfVca_t+dwpvvoVWyca+NzOTAn7z1MLqJdXxF@mail.gmail.com> (raw)
[-- 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.
next reply other threads:[~2011-02-27 12:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-27 11:44 Rocky Bernstein [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimGfVca_t+dwpvvoVWyca+NzOTAn7z1MLqJdXxF@mail.gmail.com \
--to=rocky@gnu.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).