From: dana <dana@dana.is>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Clarify documentation of parameter-assignment behaviour
Date: Wed, 17 Oct 2018 15:37:19 -0500 [thread overview]
Message-ID: <CB42153D-E0FA-4EA4-BB41-85E83EB5CF89@dana.is> (raw)
Someone asked on IRC if it was 'safe' to perform an assignment like a=$b when
sh_word_split is enabled. I quoted the documentation where it says that the RHS
is always expanded as a single string, but then i realised that this isn't
actually as explicit as it seems when it comes to 'splitting' features like
sh_word_split. Consider the following:
% a='foo bar'
% ( setopt sh_word_split; b=$a; typeset b )
b='foo bar'
% ( b=$=a; typeset b )
b='foo bar'
% ( b=${(s< >)a}; typeset b )
b='foo bar'
In each case, it's not unreasonable to assume (IMO) that the value of b will be
the result of *splitting and then rejoining* the expanded value of a, similar to
what you'd get if a was an array. But that's not what happens — the splitting
operation is effectively ignored in all three examples. To get the other
behaviour, you can nest the expansion:
% a='foo bar'
% ( setopt sh_word_split; b=${${a}}; typeset b )
b='foo bar'
% ( b=${${=a}}; typeset b )
b='foo bar'
% ( b=${${(s< >)a}}; typeset b )
b='foo bar'
Hopefully this explains it without being too confusing?
dana
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 9ad228679..4fabbe5c5 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -54,7 +54,10 @@ indent(var(name)tt(=)var(value))
In scalar assignment, var(value) is expanded as a single string, in
which the elements of arrays are joined together; filename expansion is
-not performed unless the option tt(GLOB_ASSIGN) is set.
+not performed unless the option tt(GLOB_ASSIGN) is set, and the effects
+of `splitting' features (the tt(SH_WORD_SPLIT) option, the tt($=)var(name)
+expansion form, and expansion flags like tt(f) and tt(s)) are not applied
+to outer-level parameter expansions.
When the integer attribute, tt(-i), or a floating point attribute, tt(-E)
or tt(-F), is set for var(name), the var(value) is subject to arithmetic
next reply other threads:[~2018-10-17 20:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-17 20:37 dana [this message]
2018-10-17 22:26 ` Bart Schaefer
2018-10-17 22:56 ` dana
2018-10-17 23:29 ` 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=CB42153D-E0FA-4EA4-BB41-85E83EB5CF89@dana.is \
--to=dana@dana.is \
--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).