Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Chet Ramey Newsgroups: gnu.bash.bug Subject: Re: Bash parameter transforamtion on empty array triggers unset variable. Date: Wed, 12 Aug 2020 09:49:05 -0400 Organization: ITS, Case Western Reserve University Lines: 57 Approved: bug-bash@gnu.org Message-ID: References: <3ddb8a56-c7d0-b87e-8bb4-520acecc90d5@case.edu> <6afdb56d-5dff-e780-e794-8c053fb166ee@case.edu> Reply-To: chet.ramey@case.edu NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: usenet.stanford.edu 1597240155 2536 209.51.188.17 (12 Aug 2020 13:49:15 GMT) X-Complaints-To: action@cs.stanford.edu Cc: chet.ramey@case.edu, chet@cwru.edu, bash-testers@cwru.edu, bug-bash@gnu.org To: Andrew Neff Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1597240150; bh=vcL7iVyL8HXg7XVGAMQ3IQ4lrTwIAt8TDmsBKn2i4Qk=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=7RkJF1nXIJ9jTIMCxznjhuPxPV1qAbjND1bt5Pr9nXat2VJPVPBFkgig3tg0cFd2Po QhIHWTrqLjHUvGXVATF3xBAU2DOKGvGFaLz3BvqIIbc3LBmUvSuJ2LGr/B/LFKujxXz 5DlvUZNrcgnxGzkCH5BzDJ4fMe8Qx7eAbPICzObMXDTJS/mN8KELRX5dWhZo5U6NLGU vBKVjtCn3c7n9R9oBWvdL6UKFbGbRoOT0Q6PbCdJQMHFxEQpzL3SdTr7SD/fnvpFJvf x5U8s4MbcAVre9JxcFPsG9ODvJCw9MqP3jbCcKm/LhQ0DCqbrjHap7PpMt/1bmrpfjA 519o7qeg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1597240149; bh=/kLsIKGcwUlnvFpSJk6Np/t+N8RSsls1k4HSLV9NUBU=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=KehM/wOOeIHHuCbE05sj3ELp/vcjQYxx/FC2yvqpQK1ewIaYl4svndupaJQsEfyrJ5 gXQ9SVBPZ4VhK3degPhHAp8rWp+1iVs7xZ2TsO1/OzPOu+Q7Q7vSLAnUN8+Z7tEI+lO mV1l9+jRyFwa3uG7LeGGwqlJBXZiPI2+09SeF73Di2coG0XYp2bj7TY7prKQU6BcrFQ WBpJz3gxtnZPATia4y4pWnxnTKiaPF++EVgTRn+hCqVUJHQqII+iIk7OZR4fIRL67+U em9icMX8G9CvVSs1gt+f33wCWvVa3cMc68/EgAToEi2Oe8nH8YFcdT4Nlrx1yVjfQRh 5KrwuhNg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=g-case; h=reply-to:cc:subject:to:references:from:autocrypt:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=/kLsIKGcwUlnvFpSJk6Np/t+N8RSsls1k4HSLV9NUBU=; b=VFumFpYqCCLe0BIICCrlx/KuPiEcSOS+HjPhaPfDaAyY1KO6DXZqUOKP19Di74CzNj g/C8ZUJNs2k745iU+w9hlMHQ5xEMuIDkXzym+25REPnzobXzPzXKZ9UzfZ2M7sHG3pc7 n+3q+AiFgIlAH/pJTmDoNSQT/f4EdKNOna34AjGLMpNynhgAwAFF1PLGaBGHU0SuOPQR qRHXeeT13qpPx/8DrPbrNTTci8AdPMyu/yCuFPtt90HAM0/NfdC/TYYrumCSD6NgFY7s fjG138OFQHh37fROA53crqPugtt92LoOzv6eK2zFBO4JA97mn1TQqa/9oGnQPjS1tze2 VsCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:cc:subject:to:references:from:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=/kLsIKGcwUlnvFpSJk6Np/t+N8RSsls1k4HSLV9NUBU=; b=si2t0YBCT21zZWEezhkUsWl/wn5ho+hXpp4pk81hx76sMUsGaRE0pyIxGWju5s3NBM hP8WPUudOnCqvii+8hyNqOdpoWShbujURIsyoPt20y/e/aDSNaQ56c3l+7y8/pB6qrW/ T7XizaQVyPV06zZ2HyXKMd16LEntLDRA7uqJ4z8HpiSstbNA2ZeM7TG1vmJpCZvyqCr7 Czt8y52f4vvctJrkBjBP11Z126n4LmYfylEwovwcd1uje4abKpHcYBmzInXjjV/0ik9K GQ0aj8e7tMFiJWwUAat8Q5+h+rCOnv1aFChtybdXZobSFCFg3zPFKT5GKcmOuVEMsF57 BuCw== X-Gm-Message-State: AOAM530gINa4JJQIW1IYhM6IzdQOWT0qHG05QZKreUySEtK+AXT/EItH Zgu4icwJw+BLdlMbDz/xjPGM3Wt0hE3LEgQagt5N256OccrkSve7JkdM3EUHJ+pXr7B1dQipnzH 1R/K+nGM6s/g= X-Received: by 2002:a37:8c82:: with SMTP id o124mr5802138qkd.35.1597240147857; Wed, 12 Aug 2020 06:49:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM4pIcGD2Fghhgyns3zp9AxK2aKINln80uGpIDCOevPjMyS/VYc4I1KeMPNHrRMw06d+fzJA== X-Received: by 2002:a37:8c82:: with SMTP id o124mr5802112qkd.35.1597240147523; Wed, 12 Aug 2020 06:49:07 -0700 (PDT) Autocrypt: addr=chet.ramey@case.edu; prefer-encrypt=mutual; keydata= mQGiBEEOsGwRBACFa0A1oa71HSZLWxAx0svXzhOZNQZOzqHmSuGOG92jIpQpr8DpvgRh40Yp AwdcXb8QG1J5yGAKeevNE1zCFaA725vGSdHUyypHouV0xoWwukYO6qlyyX+2BZU+okBUqoWQ koWxiYaCSfzB2Ln7pmdys1fJhcgBKf3VjWCjd2XJTwCgoFJ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) Gecko/20100101 Thunderbird/68.11.0 In-Reply-To: Content-Language: en-US X-Mirapoint-IP-Reputation: reputation=Good-1, source=Queried, refid=tid=0001.0A020301.5F33EA46.002F, actions=tag X-Mirapoint-IP-Reputation: reputation=good-1, source=Fixed, refid=n/a, actions=tag X-Junkmail-Status: score=8/80, host=mpv3-2015.case.edu X-Junkmail-PrAS-Raw: score=8/80, refid=2.7.2:2020.8.12.125417:17:8.317, ip=, rules=__YOUTUBE_RCVD, DKIM_SIGNATURE, __X_GOOGLE_DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __MULTIPLE_RCPTS_CC_X2, __SUBJ_REPLY, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __TO_MALFORMED_2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_ENDS_IN_SLASH, __URI_NO_WWW, __CP_URI_IN_BODY, __FRAUD_CONTACT_ADDY, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __MAIL_CHAIN, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODYTEXTP_SIZE_3000_LESS, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 Received-SPF: pass client-ip=129.22.103.194; envelope-from=chet.ramey@case.edu; helo=mpv3-2015.case.edu X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/12 09:49:09 X-ACL-Warn: Detected OS = Linux 2.4.x-2.6.x [generic] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: <6afdb56d-5dff-e780-e794-8c053fb166ee@case.edu> X-Mailman-Original-References: <3ddb8a56-c7d0-b87e-8bb4-520acecc90d5@case.edu> Xref: csiph.com gnu.bash.bug:16743 On 8/11/20 11:45 AM, Andrew Neff wrote: > Ah, I see the confusion. > > The issue you pointed out, "@Q breaks set -o nounset" refers to quote > parameter expansion, as does the line in CHANGES-5.1, 1.q, which makes > sense to call this a bug that was allowed in bash 4.4 and 5.0. Not quite. The report revealed that none of the parameter transformations obeyed `set -u'. The fix was to make that happen, so that parameter transformations were aligned with the other word expansions. > I should have specified, the focus of this issue is the "@a" expansion. Sure, you want an exception. > It > makes sense that @Q/E/P/A expansion should not work on unset variables with > nounset enabled. However, @a is uniquely different, in that it does not > have to do with the value of the variable, but rather the variable type. This is why it works on unset variables when `set -u' isn't enabled. The question is whether that makes it special enough to be an exception. > Here are 3 specific details I would like to address: > > 1. @a expansion should work on unset variables with "set -u" in bash 5.1. > It seems like the correct thing to do. Only @a expansion. This has been a > very useful feature in bash 4.4 and 5.0. OK, you found it useful in something you wanted to do. You're restating the proposition. > > 2. With "set -u", the following works in bash 4.4 or newer (and makes sense > that it works): (set -eu; x=(); echo "${x[@]}") > Here x is not unset, it is set to an empty array. This expansion make sense > with nounset turned on because x is not unset, it is set to () That's not why. The variable is indeed unset. The reason it doesn't fail is because there's a special POSIX carveout for $@ with no positional parameters and I extended it to ${var[@]}. The expansions of $@ and ${A[@]} parallel each other in just about every other way, so it made sense. > 3. The same as #2, but for associative arrays > Works: (set -eu; declare -A x=(); echo "${x[@]}") The same carveout for ${A[@]}. So I guess the question is whether or not @A and @a are exceptional enough. -- ``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/