bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [BUG] 'unset' fails silently under specific conditions


From: Robert Elz
Subject: Re: [BUG] 'unset' fails silently under specific conditions
Date: Wed, 02 May 2018 04:42:01 +0700

    Date:        Tue, 1 May 2018 14:36:29 -0400
    From:        Chet Ramey <chet.ramey@case.edu>
    Message-ID:  <71d753dc-036f-7fd7-d703-408c3f8ac202@case.edu>

  | OK, so which is it? Does an assignment statement preceding a special
  | builtin in a shell function create a local variable (as we discussed
  | just yesterday) or does it create a global variable because `Posix'?

Unless the variable didn't exist already, it creates nothing.   It sets the
variable for the purposes of the special builtin (and exports it) and
according to posix allows those values to persist in the current env
(though doing that is stupid .. just a bug in earlier implementations).

There is nothing related to local variables here at all, and no reason
at all for one to be created - just the globals.

The earlier test case had the "typeset" command added, which is non-standard
and so can do anything - including making local variables (though personally
I'd suggest it should do that only if called using its "local" alias, or when 
given an option to request that behaviour- there should be a way for a function
to alter the attributes of global variables).

  | Because if it creates a local variable, that's the one the `unset'
  | builtin unsets, leaving the global variable created by the first
  | assignment statement untouched.

Here, it doesn't - it was the typset that created the local variable
(and then we can have our long running discussion about the
nature of local vars and the model they should implement) but
that is not relevant to this example from Martijn.

kre





reply via email to

[Prev in Thread] Current Thread [Next in Thread]