bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Declaring a local variable circumvents "-e"


From: Chet Ramey
Subject: Re: Declaring a local variable circumvents "-e"
Date: Wed, 24 Sep 2008 23:50:09 -0400
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)

Björn Augustsson wrote:

> Bash Version: 3.2
> Patch Level: 33
> Release Status: release
> 
> Description:
> 
>         The test case below is pretty self-explanatory.
>         The assignment in fun_bad() doesn't exit the shell,
>         despite the "set -e".
> 
>         This is the version in Fedora 8.
>         Also happens on
>         * Bash Version: 3.1 Patch Level: 17 (Ubuntu Dapper)
>         * Bash Version: 3.2 Patch Level: 0 (from ftp.gnu.org))
> 
> 
> Repeat-By:
> 
> -----------------------------8<-------------------------
> #!/bin/bash
> 
> set -e
> 
> fun_bad() {
>         local bah=$( false )
> }
> 
> fun_good() {
>         local bah
>         bah=$( false )
> }
> 
> echo "start"
> 
> fun_bad
> echo "FAIL"
> fun_good
> echo "(Does not get here.)"

This isn't a bug.

The `local' command returns success if the variable assignment succeeds,
which it does.  The command substitution doesn't affect its exit status.
This is how all builtins that affect variable attributes (declare/typeset,
export, readonly) should behave.

A line consisting of only assignment statements returns success unless
it contains a command substitution, in which case it returns the status
of the command substitution.  This is as Posix specifies.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]