Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
How does zsh internally store and process variables?
- X-seq: zsh-workers 52505
- From: vlkr1 <vlkr1@xxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: How does zsh internally store and process variables?
- Date: Sat, 27 Jan 2024 22:00:10 +0000
- Archived-at: <https://zsh.org/workers/52505>
- Feedback-id: 72711691:user:proton
- List-id: <zsh-workers.zsh.org>
Hey there
One of the things that we are having trouble with are internal variables. We can use std::env::var("VARIABLE")
to get environment variables, but only if they are exported by the shell. For example, you would have to run export ZSH_VERSION
before it would show up, since rust's env::var()
function was only designed to handle exported scalar environment variables.
We do have a way to make the shell do this, basically calling the zsh builtin eval
to force it to export either these variables or dummy ones, and then running eval
again to unset them, but this is a pretty janky hack -- what if the user had important data stored in the internal variable $YG76987HBHLUBHJ
, or what if they didn't really want to export PS1
? Then you end up looping eval
s to try and find empty vars to throw your 5KB associative array in, or just writing shell in a multiline string to run callbacks and the task is needlessly complex.
Anyways, we wanted to implement internal variable inspection, but was very confused trying to understand the code. We would like to know the following:
- how zsh handles its variables
- how its variables are exported (setenv?)
- If the keys and values are copied or expected to be leaked/alloccd with malloc by the caller
Could you help us out here?
"Don't believe everything you read on the internet just because there's a picture with a fancy quote next to it." - Abraham Lincoln
Messages sorted by:
Reverse Date,
Date,
Thread,
Author