Re: [preliminary patch] test -v VARNAME

2017-03-25 Thread Martijn Dekker
Op 26-03-17 om 01:40 schreef Thorsten Glaser:
> Martijn Dekker dixit:
> 
>> This patch adds a unary -v operator to test/[/[[ to check if a variable
>> is set, like in ksh93, bash and zsh.
> 
> Eh? Isn’t that the same as [[ -n ${var+x} ]] ?

Yes. Advantage being that -v allows testing a variable name stored in a
variable without using 'eval'. And simpler syntax.

Thanks for the pointers, I'll take a look in the next few days.

- M.


Re: [preliminary patch] test -v VARNAME

2017-03-25 Thread Thorsten Glaser
Martijn Dekker dixit:

>This patch adds a unary -v operator to test/[/[[ to check if a variable
>is set, like in ksh93, bash and zsh.

Eh? Isn’t that the same as [[ -n ${var+x} ]] ?

>The one thing I haven't got working is
>
>   foo[2]=bar
>   [[ -v foo[2] ]]
>
>I haven't figured out how to get it to parse array subscripts. Any
>pointers appreciated.

Basically the same as the other code that does this ;) although… ugh.

eval.c:varsub() just calls global() which creates the variable globally
(but unset) if it doesn’t exist. But because not just array refs but
also namerefs need to be honoured, global() and local() are the only
entry points into this.

I’ll have to find a better way to do this eventually, but for now,
calling global() is no worse than the equivalent POSIX substitution
does. I’m thinking of freeing stuff if global() created it, but meh.
Adding a flag to global() to avoid creation similarily has too much
impact (too many callers). I might factor out the lookup part tho…

bye,
//mirabilos
-- 
(gnutls can also be used, but if you are compiling lynx for your own use,
there is no reason to consider using that package)
-- Thomas E. Dickey on the Lynx mailing list, about OpenSSL