Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: hzoli change: $foo:s//r/



Thorsten Meinecke wrote:
> In plain unmodified hzoli10.3 the unadorned backslash does exactly that.
> 
> $ ./zsh -fc 'echo $ZSH_VERSION
>              array=(a b c d e)
>              echo $array:s/\/\&-\&/
>             '
> 2.6-beta10-hzoli10.3
> a-a b-b c-c d-d e-e
> $
> 
> Is this just another undocumented feature? Since there's no real need
> to escape the delimiter--just choose a different one--the backslash 
> seems one of the best choices to denote "substitute whole string/ele-
> ments of array" to me. 

Yes, it really works.  This is because the backslash is removed as a nularg.
However it does not work if the substitution is quoted with double quotes.

There is a bug here I discovered testing this: nulargs are not properly
removed from the substitution strings.  This bug is also present in stock
beta10 zsh.  The patch below fixes that.  After the patch :s/''/\&-\&/ will
also do the same as :s/\/\&-\&/ but the '' syntax is more readable I think
(and also in the future \ may quote the separator string so I wouldn't
recommend its usage).

> Sincere apologies for my GNUisms breaking hzoli10.2.
> Please forgive me.
>   Thorsten

It is partially my mistake.  I knew that -q is not a universal grep option but
somehow I forgot it.  If I had tried configure on all systems I have acess to
befor releasing 10.2 I would have noticed it.

> BTW it is "substitution", isn't it?

Yes.

Zoltan

*** 1.14	1995/07/10 18:02:35
--- Src/subst.c	1995/08/16 11:48:46
***************
*** 1482,1491 ****
  		}
  		for (tt = hsubl; *tt; tt++)
  		    if (INULL(*tt))
! 			chuck(tt);
  		for (tt = hsubr = ztrdup(ptr2); *tt; tt++)
  		    if (INULL(*tt))
! 			chuck(tt);
  		ptr2[-1] = del;
  		if (sav)
  		    ptr3[-1] = sav;
--- 1482,1491 ----
  		}
  		for (tt = hsubl; *tt; tt++)
  		    if (INULL(*tt))
! 			chuck(tt--);
  		for (tt = hsubr = ztrdup(ptr2); *tt; tt++)
  		    if (INULL(*tt))
! 			chuck(tt--);
  		ptr2[-1] = del;
  		if (sav)
  		    ptr3[-1] = sav;



Messages sorted by: Reverse Date, Date, Thread, Author