zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Clarify documentation of parameter-assignment behaviour
@ 2018-10-17 20:37 dana
  2018-10-17 22:26 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: dana @ 2018-10-17 20:37 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-17 23:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17 20:37 [PATCH] Clarify documentation of parameter-assignment behaviour dana
2018-10-17 22:26 ` Bart Schaefer
2018-10-17 22:56   ` dana
2018-10-17 23:29     ` Bart Schaefer

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).