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


Groups > gnu.bash.bug > #15716

Re: Two states of empty arrays

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Clint Hepner <clint.hepner@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Two states of empty arrays
Date Thu, 12 Dec 2019 14:06:06 -0500
Lines 55
Approved bug-bash@gnu.org
Message-ID <mailman.739.1576177562.1979.bug-bash@gnu.org> (permalink)
References <c9224e23-ff7d-ba84-dc4f-aa68db902f72@noiraude.net> <CAKjp4B5tWjn-ttRuBu88EvpxuNFZo08PXouNODyJk=gwdyFD1w@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1576177562 31352 209.51.188.17 (12 Dec 2019 19:06:02 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash <bug-bash@gnu.org>
To Léa Gris <lea.gris@noiraude.net>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K+wrP0f0QTFzHsX68et6WsGCJKddYqyUZ/HSjYZbF1A=; b=GIn7jypk9hMaTucStUQguoZW9XSMzqA0L+LEmvy39q8fA2VlilmuwwZoRZEy/C9XUo UHfsibJPNarVxFiv1iQxbjGmhoHhyxn19l8nSI3sa25p1dJvM9cu3vUatrMMDj4O60rb wkKXz46M8hXwpTcuOsGWUCOSyMiy8/o3ep6zXGNE7GaX7+sFBbiMtmUFC5hCXV6Hc92f 5zkFEm4mMu7j7sOenpEIleCa7M2IuUvR/AJ+rIcEqARSiujhE266IHfZ5/dqp152s9cR vy2hYj6fO/KW+Z8EdKzrSoKmfpzRSKY7Cv2jtriiiiK78rbiG93UfjwDiXguJqx9+jOq yB6A==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K+wrP0f0QTFzHsX68et6WsGCJKddYqyUZ/HSjYZbF1A=; b=Adh9y2cAZrpU05SSEMF/SmRmmGb9PonLhxetHHKlp/FvMwxWqNFAZqZ6S/wJZ4p8EA 6KWxK21tQWbXyM5gIb/ynxQ62L6z+idU+joO1lijorVFrWeRFJf1GKFAqQNcUHKM6iFt gFwkZNF4H5tRG3W8AFk0Err6XDIr18yegyb682nqVFU+7mRP8hzrWG4fvUzPLFwj1zBM fEPqvelFwIljC5SX1rn03z0oPx5BB+QHwGwmLyEr1NCygcatS2CCL8GTQB5YNPGeHoNN QfaeevZGrcVciPW5BN0spKxHDRciwONSgL149jg3pKnfkl3mJU+zYPLwkzePF5WdNPXc aCfQ==
X-Gm-Message-State APjAAAV9Voa73o1bI5QCCspBg5ElgmG4hwcA8BqXuu7u2rt84KJs+k+O Jx7zC/DJO/J0EopgP5hMUoPItGzaX3X4yCwn1r7vJ9StlTk=
X-Google-Smtp-Source APXvYqxiQxGJb+Ydh5l9lnQ5shh66oX9VkX2IWa9MWVcPMT9hEEusDzuL3O2L3oSzXfUKBvkhc1lf6Ogy0FTsj3g1E0=
X-Received by 2002:a05:6214:448:: with SMTP id cc8mr9732225qvb.10.1576177557539; Thu, 12 Dec 2019 11:05:57 -0800 (PST)
In-Reply-To <c9224e23-ff7d-ba84-dc4f-aa68db902f72@noiraude.net>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::f2b
X-Content-Filtered-By Mailman/MimeDel 2.1.23
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
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 <https://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>
X-Mailman-Original-Message-ID <CAKjp4B5tWjn-ttRuBu88EvpxuNFZo08PXouNODyJk=gwdyFD1w@mail.gmail.com>
X-Mailman-Original-References <c9224e23-ff7d-ba84-dc4f-aa68db902f72@noiraude.net>
Xref csiph.com gnu.bash.bug:15716

Show key headers only | View raw


On Thu, Dec 12, 2019 at 1:10 PM Léa Gris <lea.gris@noiraude.net> wrote:

> Hello,
>
> Depending on how an empty array is declared, it is not stored with the
> same state.
>
> # Empty array declared without parenthesis
> unset myArr
> declare -a myArr
> typeset -p myArr
> echo "${#myArr[@]}"
>
> output:
> declare -a myArr
> 0
>

Here, you haven't yet defined a parameter named myArr; you have only set
the array
attribute on the name myArr. You can see something similar with other
attributes:

$ declare -i x
$ [[ -v x ]] || echo "x not defined"
x not defined
$ declare -p x
declare -i x


>
> # Empty array declared without parenthesis
> unset myArr
> declare -a myArr=()
> typeset -p myArr
> echo "${#myArr[@]}"
>
> output:
> declare -a myArr=()
> 0
>
>
With the assignment, you have an actual parameter named myArr. Continuing
the integer attribute
example from above,

$ x=3
$ declare -p x
declare -i x="3"
$ [[ -v x ]] || echo "x not defined"   # No output


--
Clint

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


Thread

Re: Two states of empty arrays Clint Hepner <clint.hepner@gmail.com> - 2019-12-12 14:06 -0500

csiph-web