* Re: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter
@ 1999-03-16 11:50 Sven Wischnowsky
1999-03-25 12:00 ` ${...:-...} again and subst clarification E: " Andrej Borsenkow
0 siblings, 1 reply; 2+ messages in thread
From: Sven Wischnowsky @ 1999-03-16 11:50 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson wrote:
> > The behavior is a bit weird, though, because `${foo-bar}' uses
> > `multsub', too. I haven't changed the call to it, yet, so the result
> > is that the `bar' is broken into an array -- always. This means that
> > `${#:-$foo}' will yield `1' for strings and the number of elements
> > if `bar' is `$baz' where `baz' is an array. I didn't change it
> > because I wanted to ask what it should do first, suggestions are:
> >
> > 1) let it treat the `bar' always as a string (i.e. let it never be
> > split into array elements); I guess this is what most people
> > would expect (and in the manual the thing is called `word')
>
> Since (without shwordsplit)
>
> % args() { print $#; }
> % args ${foo:-foo bar}
> 1
>
> this is the natural thing to do.
I liked this one best, too, so the patch below implements it.
> > 2) like 1), but if combined with the `A' flag, let it be treated as
> > an array
>
> Some extension like this is reasonable, but the obvious candidate is
> ${(w)#:-foo bar}, which is supposed to have exactly this effect on $# for a
> string.
>
> % foo="foo bar"
> % print ${(w)#foo}
> 2
Right, hadn't thought of that.
Bye
Sven
--- os/subst.c Mon Mar 15 10:52:31 1999
+++ Src/subst.c Tue Mar 16 12:46:13 1999
@@ -1273,7 +1273,7 @@
case '-':
if (vunset) {
val = dupstring(s);
- multsub(&val, &aval, &isarr, NULL);
+ multsub(&val, NULL, &isarr, NULL);
copied = 1;
}
break;
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
* ${...:-...} again and subst clarification E: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter
1999-03-16 11:50 PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter Sven Wischnowsky
@ 1999-03-25 12:00 ` Andrej Borsenkow
0 siblings, 0 replies; 2+ messages in thread
From: Andrej Borsenkow @ 1999-03-25 12:00 UTC (permalink / raw)
To: Sven Wischnowsky, zsh-workers
> > >
> > > 1) let it treat the `bar' always as a string (i.e. let it never be
> > > split into array elements); I guess this is what most people
> > > would expect (and in the manual the thing is called `word')
> >
I just found, that ${...:-...} does not work with arrays at all
bor@itsrm2:~%> foo=()
bor@itsrm2:~%> bar=(c d)
bor@itsrm2:~%> args ${foo:-${bar}}
0
bor@itsrm2:~%> args ${foo-${bar}}
0
If this was intended, then this change is really O.K and does the right
thing. But then, it should explicitly be mentioned in manuals.
The same applies to words after %, #, /, = (without (A)) and to val in
FOO=val as well. In all these contexts array value is forced (joined) to
scalar. May be, it is needed to be explicitly stated as well (to avoid
confusion). ${...=...} case is mentioned - but, probably, it would be better
to have them explained in rules in the correct place - even more so, as the
way it is done is again inconsistent:
bor@itsrm2:~%> setopt shwordsplit
bor@itsrm2:~%> IFS="$IFS:"
bor@itsrm2:~%> foo=("x:y" "a:b")
bor@itsrm2:~%> bar=$foo
bor@itsrm2:~%> print "$bar"
x:y a:b
No word splitting. The same applies to #, % and /.
bor@itsrm2:~%> yyy=${xxx:-$foo}
bor@itsrm2:~%> print "$yyy"
x y a b
$foo is wordsplitted. the same with =.
cheers
/andrej
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-03-25 12:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-16 11:50 PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter Sven Wischnowsky
1999-03-25 12:00 ` ${...:-...} again and subst clarification E: " Andrej Borsenkow
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).