Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Clarify documentation of parameter-assignment behaviour
- X-seq: zsh-workers 43705
- From: dana <dana@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Clarify documentation of parameter-assignment behaviour
- Date: Wed, 17 Oct 2018 15:37:19 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=mh0Np6as+SbJYf/H+uKhcXKiM3rzRhcOxjjKytHnIqY=; b=Oj3StfSKoVhaFLgK8mTcu49MdlEXaKoT8ykHJMmXubslS4775L0ibiwfnhOJkkk21S z679MDpiloORbP5k1/OJON5lRcJVmTLCBKLFALPrtsOjkB3QHmHljhco2U7rrQElJjil IwDrNXy5JthVhMQOXLZuV3OLNS7ZTz2QjN5NevRp5vRiN77h61YclLxaUpF5EhpYuNk3 Wl05WvasT/AYthMpuREwfO211B12XXnKCVx3FKlkCZMn4Vyob2Lj6G7uNgJjHldBG15G pIk1ztDTLIcfaf5OBwnI9U0lTdBTkPHIOdwRtilYP1jeJ+OL2UNL/4/m/dYHeMLTrF77 WGAQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author