Re: Unset array doesn't work

2018-02-27 Thread Robert Elz
Date:Tue, 27 Feb 2018 11:18:40 -0500
From:Chet Ramey 
Message-ID:  <21679c48-4064-5683-2d5f-91bfb7668...@case.edu>

  | It doesn't. Run the following script:

OK, that looks good.  But now I am very confused.

  | You'll see that the first expansion of `$var' uses the local value of IFS,
  | the second expansion uses the default value of $' \t\n', and the global
  | value doesn't change (or get unset) outside the function.

Yes, and I was never expecting the global to be changed (that is, in this,
I didn't imagine that as a possibility).

  | The objection was that the global or previous-scope value didn't get unset
  | when using the `unset' builtin; only in the local scope was it unset.

I was in e-mail catchup mode, I am not sure I even saw the original, but I
do tend to read your messages, and what you said (12 Feb) was ...

  |  The visibility of a local variable is restricted to a function and its
  | children,

That's fine.

  | and `unset' removes the currently-visible instance.

as is that,  at least if "removes" is interpreted in one way (which the
script you sent suggests is correct).

But:

  | Removing such an instance can `unconver' an instance in a previous scope.

What's that?

That;s not what the script shows happening, the global IFS was not
"uncovered" (whatever that means). 

It was that sentence that caused my reply.

Since it does not seem to mean what I thought it meant, perhaps you could
say what it did mean?

kre




Re: Unset array doesn't work

2018-02-27 Thread Chet Ramey
On 2/27/18 11:23 AM, Chet Ramey wrote:
> On 2/26/18 11:34 AM, Robert Elz wrote:
> 
>> I believe that most shells that implement local (which is most shells) 
>> implement unset of a local as meaning the local var becomes unset,
>> not that it vanishes and the global reappears.
> 
> That was the objection: that unset in a function unset the local instance
> of the variable, and left the global instance in place.

And, as a followup, allowing `unset' in a function to remove an instance
of a variable in a previous scope, even if that scope was a function and
the variable was a local variable there, while still leaving any global
instance unchanged.

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



Re: add generated files to .gitignore

2018-02-27 Thread don fong
Chet, thanks for the suggestion.

i still wonder what's the objection to changing .gitignore?

using a separate directory to build, while i'm working on the sources,
feels less convenient.





On Sun, Feb 25, 2018 at 1:10 PM, Chet Ramey  wrote:

> On 2/25/18 2:49 PM, don fong wrote:
> > Chet, i'm not sure i understand your suggestion.
> >
> >> You don't have to build in the source directory.
> >
> > i don't see anything in the INSTALL or README files about building
> outside
> > the source dir.
> > according to INSTALL,
>
> This is a standard feature of any autoconf-generated configure script, and
> is not specific to bash. Make a directory, cd to it, run
> "bash /path/to/srcdir/configure" and configure will make sure the right
> paths end up in the generated Makefiles.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
>


Re: Unset array doesn't work

2018-02-27 Thread Chet Ramey
On 2/26/18 11:34 AM, Robert Elz wrote:

> I believe that most shells that implement local (which is most shells) 
> implement unset of a local as meaning the local var becomes unset,
> not that it vanishes and the global reappears.

That was the objection: that unset in a function unset the local instance
of the variable, and left the global instance in place.

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



Re: Unset array doesn't work

2018-02-27 Thread Chet Ramey
On 2/26/18 9:57 AM, Clint Hepner wrote:

> As you say, the intent is to use a particular value of the variable. The fact 
> that unsetting
> IFS causes it to use a default value other than an empty string seems more 
> like a concession
> to historical usage than a feature that should be explicitly used. 

Since Posix explicitly requires it, you should be able to use it.

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



Re: Unset array doesn't work

2018-02-27 Thread Chet Ramey
On 2/26/18 4:31 AM, Robert Elz wrote:
> Date:Mon, 12 Feb 2018 09:26:37 -0500
> From:Chet Ramey 
> Message-ID:  <790ade74-690f-541c-9ab4-635991744...@case.edu>
> 
>   | This is bash's dynamic scoping. The visibility of a local variable is
>   | restricted to a function and its children, and `unset' removes the
>   | currently-visible instance. Removing such an instance can `unconver' an
>   | instance in a previous scope.
> 
> Frankly this is brain dead, unset should not be unlocal (or something equiv)
> 
> eg: if I have a func
> 
>   myfunc() {
>   local IFS
>   unset IFS
>   # do some code
>   }
> 
> the very last thing that I want is for the global IFS to apply.

It doesn't. Run the following script:

func()
{
local var=$'a\tb\tc'
typeset IFS=' '

echo ${FUNCNAME}: before unset: $var
unset IFS
echo ${IFS:-null or unset}
echo ${FUNCNAME}: after unset: $var
}


IFS='%'
declare -p IFS
func
declare -p IFS

You'll see that the first expansion of `$var' uses the local value of IFS,
the second expansion uses the default value of $' \t\n', and the global
value doesn't change (or get unset) outside the function.

The objection was that the global or previous-scope value didn't get unset
when using the `unset' builtin; only in the local scope was it unset.

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