Re: declare checks on valid nameref names don't account for +=

2016-06-02 Thread Chet Ramey
On 6/2/16 3:46 AM, Grisha Levit wrote:
> Maybe this is fixed now, but the latest devel went a little overboard :)
> 
> $ declare a=a
> bash: a: nameref variable self references not allowed

Good catch; thanks for the report.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: declare checks on valid nameref names don't account for +=

2016-06-02 Thread Grisha Levit
Maybe this is fixed now, but the latest devel went a little overboard :)

$ declare a=a
bash: a: nameref variable self references not allowed

On Wed, Jun 1, 2016 at 9:45 AM, Chet Ramey  wrote:

> On 5/31/16 2:08 PM, Grisha Levit wrote:
> > On Wed, May 25, 2016 at 3:29 PM, Chet Ramey  > > wrote:
> >
> >
> > Thanks for the report.  Both of these cases should be caught
> >
> > Is it deliberate that with the latest changes a faulty += RHS causes an
> > existing valid nameref to be unset?
>
> The code has always done that.  With more error checking happening at
> assignment time instead of on reference, it's more apparent.  I'm working
> on it.
>
> > |$ declare -n ref=re $ declare -n ref+=f bash: ref: nameref variable self
> > references not allowed $ declare -p ref bash: declare: ref: not found $
> > declare -n ref=X $ declare -n ref+=/ bash: declare: `/': not a valid
> > identifier $ *declare* -p ref bash: declare: ref: not found|
> >
> > Also, this still seems to miss some stuff that would normally be caught:
> >
> > |$ declare -n ref=ref[0] bash: declare: ref: nameref variable self
> > references not allowed $ declare -n ref=re ref+=f[0] $ declare -p ref
> > declare -n ref="ref[0]" |
>
> Yes, though you still can't use it.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRUc...@case.edu
> http://cnswww.cns.cwru.edu/~chet/
>


Re: declare checks on valid nameref names don't account for +=

2016-06-01 Thread Chet Ramey
On 5/31/16 2:08 PM, Grisha Levit wrote:
> On Wed, May 25, 2016 at 3:29 PM, Chet Ramey  > wrote:
> 
> 
> Thanks for the report.  Both of these cases should be caught
> 
> Is it deliberate that with the latest changes a faulty += RHS causes an
> existing valid nameref to be unset?

The code has always done that.  With more error checking happening at
assignment time instead of on reference, it's more apparent.  I'm working
on it.

> |$ declare -n ref=re $ declare -n ref+=f bash: ref: nameref variable self
> references not allowed $ declare -p ref bash: declare: ref: not found $
> declare -n ref=X $ declare -n ref+=/ bash: declare: `/': not a valid
> identifier $ *declare* -p ref bash: declare: ref: not found|
> 
> Also, this still seems to miss some stuff that would normally be caught:
> 
> |$ declare -n ref=ref[0] bash: declare: ref: nameref variable self
> references not allowed $ declare -n ref=re ref+=f[0] $ declare -p ref
> declare -n ref="ref[0]" |

Yes, though you still can't use it.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: declare checks on valid nameref names don't account for +=

2016-05-31 Thread Chet Ramey
On 5/31/16 3:40 PM, Grisha Levit wrote:
> Also seems like after an invalid nameref assignment is encountered,
> |declare| works oddly on remaining assignments that are part of the same
> command:

Thanks.  This was an easy fix.

Chet



-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: declare checks on valid nameref names don't account for +=

2016-05-31 Thread Grisha Levit
Also seems like after an invalid nameref assignment is encountered, declare
works oddly on remaining assignments that are part of the same command:

$ *unset* -n bad good
$ declare -n bad+=. good=var
bash: declare: `.': not a valid identifier
$ *declare* -p good
declare -- good="var"# created, but not a nameref

$ *unset* -n bad good
$ declare -n good=var; declare -n bad+=. good=foo
bash: declare: `.': not a valid identifier
$ *declare* -p good
declare -n good="var"# not modified

$ *unset* -n bad good
$ declare -n good=var; declare -n bad+=. good=var
bash: declare: `.': not a valid identifier
bash: var: nameref variable self references not allowed   # ??

​


Re: declare checks on valid nameref names don't account for +=

2016-05-31 Thread Grisha Levit
On Wed, May 25, 2016 at 3:29 PM, Chet Ramey  wrote:


> Thanks for the report.  Both of these cases should be caught
>
Is it deliberate that with the latest changes a faulty += RHS causes an
existing valid nameref to be unset?

$ declare -n ref=re
$ declare -n ref+=f
bash: ref: nameref variable self references not allowed
$ declare -p ref
bash: declare: ref: not found

$ declare -n ref=X
$ declare -n ref+=/bash: declare: `/': not a valid identifier
$ *declare* -p ref
bash: declare: ref: not found

Also, this still seems to miss some stuff that would normally be caught:

$ declare -n ref=ref[0]
bash: declare: ref: nameref variable self references not allowed
$ declare -n ref=re ref+=f[0]
$ declare -p refdeclare -n ref="ref[0]"

​


Re: declare checks on valid nameref names don't account for +=

2016-05-25 Thread Chet Ramey
On 5/22/16 7:14 PM, Grisha Levit wrote:
> The following should probably work:
> 
> |$ declare -n ref=var ref+=[@] bash: declare: [@]: invalid variable name for
> name reference |
> 
> But the following should not:
> 
> |$ declare -n ref=re ref+=f $ declare -p ref declare -n ref="ref" |
> 
> The latter causes a segfault for export/readonly.

Thanks for the report.  Both of these cases should be caught.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



declare checks on valid nameref names don't account for +=

2016-05-22 Thread Grisha Levit
The following should probably work:

$ declare -n ref=var ref+=[@]
bash: declare: [@]: invalid variable name for name reference

But the following should not:

$ declare -n ref=re ref+=f
$ declare -p refdeclare -n ref="ref"

The latter causes a segfault for export/readonly.
​