Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: =?utf-8?Q?Lawrence_Vel=C3=A1zquez?= Newsgroups: gnu.bash.bug Subject: Re: set -u not working as expected Date: Sat, 1 Aug 2020 20:47:42 -0400 Lines: 68 Approved: bug-bash@gnu.org Message-ID: References: <000301d66834$588493c0$098dbb40$@kalvr.net> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.15\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1596329271 26541 209.51.188.17 (2 Aug 2020 00:47:51 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Kristof Burek Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=larryv.me; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=fm1; bh=D 5NXVnOKW5TmE08B4gKk/knMhaGutpP7tV79f74CEoU=; b=dmLf1ujBpRT7q1Bj4 qktzXPAEduRk5aX682Y8h8bCtLl+YkONhXq1m9PBAqmONQrI+FjNfatxuFhVhBhs Ib5ifmofJERnjoGKF/YhcwmyIXZYAkxm/43JQovqgTOI6NeFvbRikC9Y2Yp8TDCt oRxB+KyR4D/i87HEUKSEP8PxxDCCMn8z6BEkCnCFvHcAnDqIKaF7D+BF3uSL2vFj eU9QsaSWgzqO0+sG0NTTlmJuwq+ZjCGzpxbdYnaAMtEJQGI5AaXO3R2CT83h2RDj LEnw8dUT+8MZjWFrchZWpB84o1RGC9KA9LtU2A+0I1exAqS1lgJTpkxKgd53z75m mmNVQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=D5NXVnOKW5TmE08B4gKk/knMhaGutpP7tV79f74CE oU=; b=ixhvjuGXypRDKdFb+ElSzwp/y+HzTs98cXciFZtRTN19kLgCW3lIMDvq2 KEHt7U3V2gm59yEHT7oIZQaMrDL24JVgb+YTQnQ4Y2HlORk6PdxgG9ev0B7ylQVO gGUmiqGRIix+mrSFe38mpqD2hu5c/BMnFmHkjxJLjMnHZtAh0evtsVXwPBIENC+D 4V6IbM3i3ttE99wYZEFGb1enpF7krmFJ4FEvFdLiVA8+fDEbpqxjUzi0Qbfvs50p HVs/sWTG9I88ohKCaDSAypE/HhJ9hfQ8ykN21BqzfGY2YlOt9Ns1av2m4+lvbnPP LZnEvvlMhkKnP/mPTapWoGE6MgTNA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrjedugdegtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurheptggguffhjgffgffkfhfvofesthhqmh dthhdtjeenucfhrhhomhepnfgrfihrvghntggvpgggvghljoiiqhhuvgiiuceovhhqsehl rghrrhihvhdrmhgvqeenucggtffrrghtthgvrhhnpedukeejtdelhedvudfhveelgeetff etkeehvdehjeetleffvdegtdejvdeuueegieenucfkphepuddttddruddvrddujeekrddv feenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehvqh eslhgrrhhrhihvrdhmvg X-ME-Proxy: In-Reply-To: <000301d66834$588493c0$098dbb40$@kalvr.net> X-Mailer: Apple Mail (2.3445.104.15) Received-SPF: pass client-ip=64.147.123.21; envelope-from=vq@larryv.me; helo=wout5-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/01 20:47:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-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: X-Mailman-Original-References: <000301d66834$588493c0$098dbb40$@kalvr.net> Xref: csiph.com gnu.bash.bug:16671 > On Aug 1, 2020, at 2:48 PM, Kristof Burek wrote: >=20 > set -u # Bash complains and exits on first use of an unbound name With respect to set -u neither the bash man page nor POSIX.1-2017 refer to "use" of parameters, but to their *expansion*. > s+=3D't' # Line 8 - Bash should fail here I don't see any parameter expansion here, and ksh and zsh agree: % bash --version | head -n 1; ksh --version; zsh --version GNU bash, version 5.0.17(1)-release (x86_64-apple-darwin18.7.0) version sh (AT&T Research) 93u+ 2012-08-01 zsh 5.8 (x86_64-apple-darwin18.7.0) % bash -c 'set -u; unset s; s+=3Dt; printf "<%s>\\n" "$s"' % ksh -c 'set -u; unset s; s+=3Dt; printf "<%s>\\n" "$s"' % zsh -c 'set -u; unset s; s+=3Dt; printf "<%s>\\n" "$s"' Presumably none of these shells implements s+=3Dt as s=3D${s}t. > #t=3D'' > t=3D${t}'t' # Line 12, Bash fails until line 11 loses its starting # This fails as you expect because you're expanding $t in there. > u+=3D('t') # Line 15, Bash should fail here Again, I don't see any parameter expansion here, and ksh and zsh agree: % bash -c 'set -u; unset u; u+=3D(t); printf "<%s>\\n" "${u[@]}"'=20 % ksh -c 'set -u; unset u; u+=3D(t); printf "<%s>\\n" "${u[@]}"'=20 % zsh -c 'set -u; unset u; u+=3D(t); printf "<%s>\\n" "${u[@]}"'=20 Presumably none of these shells implements u+=3D(t) as u=3D("${u[@]}" = t). > let v+=3D1 # Line 18, Once line 11 is uncommented, Bash fails here I haven't seen the code for arithmetic expansion, but I assume it treats v+=3D1 as morally equivalent to v=3D${v}+1 (=C3=A0 la C99). Thus = there *is* an expansion, which fails under set -u. Regardless of the particulars, ksh and zsh again agree: % bash -c 'set -u; unset v; let v+=3D1; printf "<%s>\\n" "$v"' bash: v: unbound variable % ksh -c 'set -u; unset v; let v+=3D1; printf "<%s>\\n" "$v"' ksh: let: v: parameter not set ksh: v: parameter not set % zsh -c 'set -u; unset v; let v+=3D1; printf "<%s>\\n" "$v"' zsh:1: v: parameter not set zsh:1: v: parameter not set > When this issue is fixed, I dare say a few perfectly working scripts > will fall over, but I hope not too many of mine. It's not clear that there's a bug here. vq=