Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail From: Dan Douglas Newsgroups: gnu.bash.bug Subject: Re: `foo=1 declare -r foo' prints an error message but its exit status is zero Date: Fri, 11 Sep 2015 02:04:07 -0500 Lines: 94 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1631624.KXbFBnMrbe"; micalg="pgp-sha1"; protocol="application/pgp-signature" X-Trace: usenet.stanford.edu 1441955106 10803 208.118.235.17 (11 Sep 2015 07:05:06 GMT) X-Complaints-To: action@cs.stanford.edu Cc: ziyunfei <446240525@qq.com> To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=ndougl.as; h=from:to:cc:subject:in-reply-to:references:mime-version:content-type; s=s1; bh=Kcu8l3qycLW/7nKrNhtmwU2m8Og=; b=Y1eodXojpK1inP+HnH+lWp3 4L6VS1ECiNPg/fBE6wC2RzfHy1vwcU3t2MHAPAFclbEQ4Uu4ZyMN3YrZMytuIDVy k+iL6lejhwRWFYtnEcrLTkGth7P3Cs69xKU5uLTletiyBCf+SksdiwYOcNs+zJwN GjoacsLenOMNJIXN+LEc= User-Agent: KMail/5.0.43 pre (Linux/4.2.0; KDE/5.14.0; x86_64; ; ) In-Reply-To: X-SG-EID: 0BFV9TQLtfCCO+MFdgK90pmh300FCxFSbG//gVweYMnE0WRRKLX25DZu6lRzJyx/fulVLL7JWDtp84 fM2r1nfO8M95WmNavJitoiIu6AwGJqMy0u5W0zUM7NbMvL6nk+HS+FIZaTxB57WpfNFcRtTSL/L5oT 3hpyQDiWZJuewMA= X-SendGrid-Contentd-ID: {"test_id":"1441955060"} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 50.31.49.42 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11486 --nextPart1631624.KXbFBnMrbe Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" On Wednesday, September 9, 2015 2:17:30 PM CDT ziyunfei wrote: > $ foo=1 declare -r foo > bash: foo: readonly variable > $ echo $? > 0 > $ echo $foo > 1 > > Is this a bug? > > $ bar=1 readonly bar; # throw an error in Bash 4.2, fixed in Bash 4.3 It's a bit more illustrative when you use `readonly' instead of `declare'. In the former case bash only prints the error in non-POSIX mode because it modifies the special builtin to unset its value when the command finishes. `declare' will print an error in either mode. If there's any bug here it's that bash fails to bail out and executes the echo command anyway. $ ( for sh in bash sh ksh mksh zsh dash bb posh; do printf '%-5s x=%5s status=%s\n' "${sh}:" "$("$sh" -c "\${ZSH_VERSION+false}||emulate sh; trap 'echo \${x+unset}' EXIT; $(