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

Re: Bug in parameter expansion with :- ?




10.01.2017, 18:56, "Ronald Fischer" <ynnor@xxxxx>:
> On Tue, Jan 10, 2017, at 16:43, Peter Stephenson wrote:
>>  On Tue, 10 Jan 2017 16:35:00 +0100
>>  Ronald Fischer <ynnor@xxxxx> 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).



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