zsh-workers
 help / color / mirror / code / Atom feed
* Bug in parameter expansion with :-    ?
@ 2017-01-10 15:35 ` Ronald Fischer
  2017-01-10 15:43   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Ronald Fischer @ 2017-01-10 15:35 UTC (permalink / raw)
  To: zsh-workers

This expands correctly to a '+':

      ${unset_variable:-+}

This however doesn't expand to a '-', but to the empty string:

    ${unset_variable:--}

I didn't find anything in the man page which would explain this
behaviour.

A note aside: Bash expands in the latter case to a dash (-). 

My zsh version:

zsh 5.1.1 (x86_64-unknown-cygwin)


Ronald


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

* Re: Bug in parameter expansion with :-    ?
  2017-01-10 15:35 ` Bug in parameter expansion with :- ? Ronald Fischer
@ 2017-01-10 15:43   ` Peter Stephenson
  2017-01-10 15:55     ` Ronald Fischer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2017-01-10 15:43 UTC (permalink / raw)
  To: zsh-workers

On Tue, 10 Jan 2017 16:35:00 +0100
Ronald Fischer <ynnor@mm.st> wrote:

> This expands correctly to a '+':
> 
>       ${unset_variable:-+}
> 
> This however doesn't expand to a '-', but to the empty string:
> 
>     ${unset_variable:--}

You may be getting into confusions with options to builtins rather than
the expansion.

% print -r -- ${unset_variable:--} 
-

pws


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

* Re: Bug in parameter expansion with :-    ?
  2017-01-10 15:43   ` Peter Stephenson
@ 2017-01-10 15:55     ` Ronald Fischer
  2017-01-10 18:41       ` Nikolay Aleksandrovich Pavlov (ZyX)
  0 siblings, 1 reply; 4+ messages in thread
From: Ronald Fischer @ 2017-01-10 15:55 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

On Tue, Jan 10, 2017, at 16:43, Peter Stephenson wrote:
> On Tue, 10 Jan 2017 16:35:00 +0100
> Ronald Fischer <ynnor@mm.st> wrote:
> 
> > This expands correctly to a '+':
> > 
> >       ${unset_variable:-+}
> > 
> > This however doesn't expand to a '-', but to the empty string:
> > 
> >     ${unset_variable:--}
> 
> You may be getting into confusions with options to builtins rather than
> the expansion.
> 
> % print -r -- ${unset_variable:--} 
> -

Yes I do! You are right - not a bug!

Ronald


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

* Re: Bug in parameter expansion with :-    ?
  2017-01-10 15:55     ` Ronald Fischer
@ 2017-01-10 18:41       ` Nikolay Aleksandrovich Pavlov (ZyX)
  0 siblings, 0 replies; 4+ messages in thread
From: Nikolay Aleksandrovich Pavlov (ZyX) @ 2017-01-10 18:41 UTC (permalink / raw)
  To: Ronald Fischer, Peter Stephenson, zsh-workers



10.01.2017, 18:56, "Ronald Fischer" <ynnor@mm.st>:
> On Tue, Jan 10, 2017, at 16:43, Peter Stephenson wrote:
>>  On Tue, 10 Jan 2017 16:35:00 +0100
>>  Ronald Fischer <ynnor@mm.st> wrote:
>>
>>  > This expands correctly to a '+':
>>  >
>>  > ${unset_variable:-+}
>>  >
>>  > This however doesn't expand to a '-', but to the empty string:
>>  >
>>  > ${unset_variable:--}
>>
>>  You may be getting into confusions with options to builtins rather than
>>  the expansion.
>>
>>  % print -r -- ${unset_variable:--}
>>  -
>
> Yes I do! You are right - not a bug!
>
> Ronald

For checking what argument is literally I would suggest `printf '<%s>' $arg` instead: this will show trailing spaces due to `<>` around `%s`, let you distinguish between variable accidentally becoming an array and determine which strings are in one array item exactly (`printf '<%s>' 1 2` results in `<1><2>`, harder to miss then a space). And this also does not look like you are fighting with zsh (`-r` and `--` are there to prevent some misinterpretations).


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

end of thread, other threads:[~2017-01-10 18:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170110153530epcas3p444d88e1dff85a69371df2472330b006b@epcas3p4.samsung.com>
2017-01-10 15:35 ` Bug in parameter expansion with :- ? Ronald Fischer
2017-01-10 15:43   ` Peter Stephenson
2017-01-10 15:55     ` Ronald Fischer
2017-01-10 18:41       ` Nikolay Aleksandrovich Pavlov (ZyX)

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