Re: `bash --debugger` in interactive mode

2012-08-19 Thread Chet Ramey
On 8/18/12 1:55 AM, 郑文辉(Techlive Zheng) wrote:
> I happened to have `shopt -s extdebug` in my .bashrc recently.
> 
> After a new bash session started, I got the following output.
> 
> bash debugger, bashdb, release 4.2-0.8
> 
> Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
> Rocky Bernstein
> This is free software, covered by the GNU General Public License,
> and you are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> 
> ** Internal debug error _Dbg_is_file(): file argument null
> bash: _Dbg_filenames[$fullname]: bad array subscript
> 
> I guess `--debugger` or `shopt -s extdebug` is not supposed to be run
> under interactive mode?
> 
> If so, maybe a detection should be done for this situation?

Thanks for the report.  I will put something in for the next bash release.

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: Bash 4.1 doesn't behave as I think it should: arrays and the environment

2012-08-19 Thread Stephane Chazelas
2012-08-17 17:18:12 -0400, Greg Wooledge:
> On Fri, Aug 17, 2012 at 03:19:56PM +0800, John Summerfield wrote:
> > In two cases I wish to pass an array in the environment, like so:
> > 14:28 john@Boomer$ STUFF[1]=one STUFFX=stuffx env | grep ^ST
> > STUFFX=stuffx
> > STUFF[1]=one
> 
> You are creating an environment variable called "STUFF[1]".  This is
> an invalid environment variable name, but env(1) receives it and
> dutifully prints it out.  However, Bash recognizes that it is an
> invalid name, and does not turn it into a usable shell variable.
[...]

Well, if it were an invalid environment variable, why would bash
pass it to env? STUFF[1] is a valid environment variable name, but
not a valid shell variable name.

> Some older versions of Bash would also strip such invalid variables
> from the environment before invoking child processes.  Bash 4.2
> leaves them in the environment because of complaints about build
> systems that were using them for some purpose.  I don't know whether
> Bash 4.1 is one that stripped them or preserved them.  In either
> case, you should not be writing programs that rely on invalid variable
> names.
[...]

It's different here. It's the shell that *sets* the STUFF[1]
env var passed to the env command, it's not about inheriting it.

Note that no other shell would put "STUFF[1]=on" in env's
environ there:

$ zsh -c 'STUFF[1]=one STUFFX=stuffx env' | grep STUFF
STUFFX=stuffx
$ ksh -c 'STUFF[1]=one STUFFX=stuffx env' | grep STUFF
STUFFX=stuffx
$ pdksh -c 'STUFF[1]=one STUFFX=stuffx env' | grep STUFF
STUFFX=stuffx
$ ash -c 'STUFF[1]=one STUFFX=stuffx env' | grep STUFF
ash: 1: STUFF[1]=one: not found
$ bourne-sh -c 'STUFF[1]=one STUFFX=stuffx env' | grep STUFF
bourne-sh: STUFF[1]=one: not found

~$ ksh -c 'STUFF[0]=one STUFFX=stuffx env' | grep STUFF
STUFF=one
STUFFX=stuffx
~$ pdksh -c 'STUFF[0]=one STUFFX=stuffx env' | grep STUFF
STUFF=one
STUFFX=stuffx
~$ bash -c 'STUFF[0]=one STUFFX=stuffx env' | grep STUFF
STUFF[0]=one
STUFFX=stuffx


(in ksh, $V is short for ${V[0]}).

-- 
Stephane





Re: `bash --debugger` in interactive mode

2012-08-19 Thread Techlive Zheng
2012/8/20 Chet Ramey :
> On 8/18/12 1:55 AM, 郑文辉(Techlive Zheng) wrote:
>> I happened to have `shopt -s extdebug` in my .bashrc recently.
>>
>> After a new bash session started, I got the following output.
>>
>> bash debugger, bashdb, release 4.2-0.8
>>
>> Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
>> Rocky Bernstein
>> This is free software, covered by the GNU General Public License,
>> and you are
>> welcome to change it and/or distribute copies of it under certain
>> conditions.
>>
>> ** Internal debug error _Dbg_is_file(): file argument null
>> bash: _Dbg_filenames[$fullname]: bad array subscript
>>
>> I guess `--debugger` or `shopt -s extdebug` is not supposed to be run
>> under interactive mode?
>>
>> If so, maybe a detection should be done for this situation?
>
> Thanks for the report.  I will put something in for the next bash release.
>
> 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/

I just want poin it out that there are some bash tricks which require
using `set -o functrace` and `shopt -s extdebug` in interactive mode
to make the DEBUG trap to be invoked in ( ) subshells, see
,
maybe this is something that should be done in `bashdb`?