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


Groups > gnu.bash.bug > #13750

Re: Unset array doesn't work

Path csiph.com!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!171.64.64.130.MISMATCH!usenet.stanford.edu!not-for-mail
From Clint Hepner <clint.hepner@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Unset array doesn't work
Date Mon, 26 Feb 2018 09:57:10 -0500
Lines 91
Approved bug-bash@gnu.org
Message-ID <mailman.9752.1519657038.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>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0 (Mac OS X Mail 10.3 \(3273\))
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1519657038 32360 208.118.235.17 (26 Feb 2018 14:57:18 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet.ramey@case.edu, bug-bash@gnu.org
To Robert Elz <kre@munnari.OZ.AU>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=fs+JJhg7izlOxzACUge/x/uM45yRz+QvdzIDdXAE/Kg=; b=jw4WfJOx2KoyQe/egMq2Ve1u/HIApDH4ta+HaG4lHTsRVNo9XyX1qsCBNlwBAXrqmQ OF8URjMI7ij+0Km5olq/1g0CXOZTVGoNha1L05w5ko2TrppL0ECoFJYlI01fXpOe8sdP rt9qhH3zPV0tafR13E96krHbVcLTsMMmPmG6pxBf9mHBBfdZb64lpemeLD0PKcBi/k8f lSBK58fsvpK8AKg8+VG+CgAY/VbZ/yToIuHIhEWpnZ8uPygzKDHULvO6XAHAkEFAJ/Mx 87LZSu0spAR5+S+U7NKOsFE2xidRape3ENWwl0T3T2ZoxwlFVRXaqTcig2bXfR1I3BRg iKNg==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=fs+JJhg7izlOxzACUge/x/uM45yRz+QvdzIDdXAE/Kg=; b=C3mKqd+FIvAAG7L7EEgTal3vll7f/wZXxyRxc+AtLakgg6OrQqpYK6HrS4pT+sXjM+ r27b4XZLWpc3xmF65wgVAu/wLw/0DbFJRR7Dy8+tuTVqm7l7p+k+hzVasb9LLTVsjXjb K8GM0RBVGyoPME/guLpGnO2NhYgg0ICUX25bv7q3kJz/SKJLFPSw76rilqA48Cmq1Z6a HjGsmQbchlRM+AJeMvL6JO7KfWRkqCrXnGFHby7NzcPvl/QVeHZm4mj/IeI4PBVbefK6 281vH5QSMsIzIzEJqIoxU4iIkVO6utH0/f2luuyzCPZKMhpzCkrtYhkPazRXamFE/iqn w72Q==
X-Gm-Message-State APf1xPBPRPGwoJ//8FexoZmFkKE+Nd48+UyAgH+SqRjRpFyz8Qjjqq6b wX76MYuFfcemPdp5S5gaMlvCz+HN
X-Google-Smtp-Source AG47ELvST5UIYrIpztvKHros3IkGe2bzQx/N9bukL0/1EDj5z4MEoS6vOFj2uk8Y4nyZEKFfy+8T0Q==
X-Received by 10.237.38.2 with SMTP id z2mr17861379qtc.319.1519657031095; Mon, 26 Feb 2018 06:57:11 -0800 (PST)
In-Reply-To <9974.1519637469@jinx.noi.kre.to>
X-Mailer Apple Mail (2.3273)
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:400d:c0d::22f
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:13750

Show key headers only | View raw


> On 2018 Feb 26 , at 4:31 a, Robert Elz <kre@munnari.OZ.AU> 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.
> 
> The intent is to use the default IFS value, which is what an unset IFS
> produces, without affecting the current global IFS setting.

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. If you need a particular
value, assign it instead of using a nonobvious alternative that is only shorter by three of characters:

    IFS=$' \t\n'
    unset IFS

> In this example, I could do IFS=$' \t\n' if I was willing to assume that $'...'
> support exists (the shell executing the script is not necessarily going to
> be bash)

You are already assuming $'...'-support if you are using local; both are bash extensions
to the POSIX standard.

If portability is your goal, making a nonstandard change to one shell isn't going to help. Suppose
bash did change the behavior of unset (even optionally) or added an "unlocal" command, and you
made use of this. Now your script is limited to bash 4.5 or newer, and *maybe* any other shell that
could be convinced to implement something similar. $'...' already enjoys wider level of support.

> or I could do
> 
> 		IFS=' 	
> '
> 
> and just hope that survives as written (it would straight from the editor,
> but who knows when someone else decides that trailing whitespace on
> lines should all be deleted).   Variants to avoid that get even uglier.

People who remove whitespace from inside quotes do so at their own risk. Not all
trailing whitespace is extraneous.

If necessary, you can define a global (at the expense of a single subprocess)

    myIFS=$(printf ' \t\n')

to get a value in a completely POSIX-compatible way you can use to assign to a localized
copy of IFS. (But I want to reiterate that you have already thrown POSIX compatibility out
the window by using local in the first place, so you might as well use $' \t\n'.)

-- 
Clint

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


Thread

Re: Unset array doesn't work Clint Hepner <clint.hepner@gmail.com> - 2018-02-26 09:57 -0500

csiph-web