Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Clint Hepner 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: References: 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 To: =?UTF-8?B?TMOpYSBHcmlz?= 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:15716 On Thu, Dec 12, 2019 at 1:10 PM L=C3=A9a Gris 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=3D() > typeset -p myArr > echo "${#myArr[@]}" > > output: > declare -a myArr=3D() > 0 > > With the assignment, you have an actual parameter named myArr. Continuing the integer attribute example from above, $ x=3D3 $ declare -p x declare -i x=3D"3" $ [[ -v x ]] || echo "x not defined" # No output -- Clint