Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: more splitting
- X-seq: zsh-users 30571
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: more splitting
- Date: Tue, 14 Apr 2026 22:58:37 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=YMADI1ajFUISNQbyQ5l2u94cBfKQUVNsWGkO45vF9IM=; fh=yk3c4scJWo86Za4IR1HBNZw2a+GkUkfVQ7Fs3jnanfg=; b=AS9yqG1/T0Lhocq50CT5baMrZaje71nheNbUl5xyhGul5uel5xAIbF6bCVpJPYBdd9 m/qh8N5sbVcJb4nuLqX+Mf7lfXVr64Mq8CnkCMG/1CnBs+jnhscC3MK7UlAl6dL715uT NIMt8D8nf4VK/9w7BmNJoCINgElQi56k5IlcZKhVSybAvm4UQerIwJrexMaEgKsezn/d zPzmucVXcYyuTJf4K10vF7VDZhIDCQER54tblOJvn7HkwqGEy8wPEa2+C+CbL5wjSjvL DRe90otY0/6SDsfsOYbAyFEFEJhP/vDaSqFq7uDzrO/MgPYvODI3ZXPQreyk/JTd2O52 VVtA==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1776232730; cv=none; d=google.com; s=arc-20240605; b=Suu06P+XobLdqU2ydfKeHvsQ4cIjLNeDpn5TN84lRLGoQjdj3xo3F1/+iQVKdhituu CZqfmrfLFwNa6DLSO6RuZZQhWrcB/AK58luNU862pQ5qadW2R2tYq2CJu6gLW+5kxnJJ qqZ1hYHcKnb54ZZNNSdKFzUMsA59kFRlUqMqfswkb89ISYZ+hLBuZligcOFDalJDrn8b Qt0tMwrnbUL/edkHHFuoDOnhGhNNUeOvMuNUM0XfTP9YEq/2qYSShmrYfJ8RK2xUb5Ht rhPsg5Bm09YzQGsepYdyjea+z5hZjc2z57wAfELJqr4dwCHZM+Sou6rnBr5rGGxZSBKJ ts7w==
- Archived-at: <https://zsh.org/users/30571>
- In-reply-to: <8041b57a-a753-46f0-bd9f-c81de3d3c988@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <711e5b5f-5bd3-44e5-87a7-e18b0d670ae5@eastlink.ca> <CAGdYchuXfLZNBY2r8ztKuBrP17BN9UZ-jy_pOXtTHUesyMCL3Q@mail.gmail.com> <CAH+w=7a1Z3T2+t5w5Y9_ODFwsDycWfejKSTL9aoukEHhqO8RxQ@mail.gmail.com> <19aa1276-5f07-4c9a-8c6f-0c460be587a1@eastlink.ca> <CAH+w=7ZrV8XciLSxg10AoJdYCRDDMj2+oZBbbor_Miiva==4pg@mail.gmail.com> <8041b57a-a753-46f0-bd9f-c81de3d3c988@eastlink.ca>
On Tue, Apr 14, 2026 at 9:44 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2026-04-14 20:26, Bart Schaefer wrote:
> > Arguments ($@) are a list of words that the shell has already divided
> > up. Pipes (and other sorts of file input) are a stream of bytes.
> Yeah, that gets to the heart of my issue. It's this 'shell has already'
> ... how?
By parsing.
> Where is the information stored?
This is almost literally the same as the distinction between a
(char[]) and a (char[][]) in C. The information is stored in a data
structure in the shell. When you write
var=("a b" c$'\n''d e f'' ''g h')
the shell parses the quoted sections and builds a data structure,
which zsh calls an array. The quotes themselves are gone, they were
only needed to tell how to build the array.
> When you say 'stream of
> bytes' in my mind that stream must include whatever information is
> needed to determine the split.
No, really, it's just a stream of bytes. It doesn't have any inherent
semantics at all. You can add things to the stream that can later be
interpreted as semantics, but then you also have to provide the
interpreter.
When you write
print -rn $var
you are instructing the shell to dump to stdout, as string, the
contents of the data structure. You haven't told it to restore the
original tokens from before the parse. In fact it can't restore the
original: as I said, those quotes are gone.
> Where else could the information reside?
In the case of $var, it's still in that array structure named "var".
But the rules for what happens when you use $var to "output" that
array depend on context. For a simple usage like
print -rn $var
the rule is to combine all the elements into a single string with
spaces between them.
If you don't want that structure information to be lost, you have to
tell zsh to re-create it. It can't promise to restore it exactly as
it was, because that's gone, but if you write
print -rn ${(q+)var}
the (q+) tells zsh to rebuild something that has the same semantics as
the original quoting. Notice that Stephane used (q+) in the original
"hex" function you posted.
If you want to see a representation of the whole internal structure
including it's name, instead of just a representation of its value,
you can write
typeset -p1 var
and then you get a similar reconstruction of the semantics (but still
not the original source).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author