Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #13758

Re: Unset array doesn't work

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Unset array doesn't work
Date 2018-02-27 11:18 -0500
Message-ID <mailman.9806.1519748341.27995.bug-bash@gnu.org> (permalink)
References <790ade74-690f-541c-9ab4-6359917442d0@case.edu> <a56e05b1-0b34-1cb2-6073-91c12f27e228@gmail.com> <a642644f-e475-6361-140e-5b47ab4e321c@case.edu> <755d61fa-d2bc-8855-bc30-4388aff40691@gmail.com> <9974.1519637469@jinx.noi.kre.to>

Show all headers | View raw


On 2/26/18 4:31 AM, Robert Elz wrote:
>     Date:        Mon, 12 Feb 2018 09:26:37 -0500
>     From:        Chet Ramey <chet.ramey@case.edu>
>     Message-ID:  <790ade74-690f-541c-9ab4-6359917442d0@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, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Unset array doesn't work Chet Ramey <chet.ramey@case.edu> - 2018-02-27 11:18 -0500

csiph-web