[Top][All Lists]

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

Re: backquotes inconsistent with errexit (set -e) and export

From: Chet Ramey
Subject: Re: backquotes inconsistent with errexit (set -e) and export
Date: Thu, 24 Jun 2004 14:17:33 -0400

> Machine Type: i386-redhat-linux-gnu
> Bash Version: 2.05b
> Patch Level: 0
> Release Status: release
> Description:
>         I use "set -e" a lot in scripts to increase brittleness. The main 
> feature is that if 
>         childprocesses return an error than the script stops and exits itself 
> with an error.

`set -e' works on simple commands, with a few exceptions detailed in the
man pages.

>         Example:
>            set -e;VVV=`false`
>         will stop any script.

An assignment statement is a simple command.  The exit status of an
assignment statement (or command consisting of only assignment
statements)  that contains a command substitution is the exit status of
the last (of possibly multiple) command substitution performed.

So the exit status of the assignment above is 1.

>         However, using the 'export' builtin will disable this behavior:
>            set -e;export VVV=`false`
>         will not stop the script.

Because, as Paul said, the `export' builtin exits successfully despite the
failure of the command substitution, as long as `VVV' had not previously
been declared read-only.

All of this is spelled out across several sections of the POSIX spec.


``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
Chet Ramey, ITS, CWRU    address@hidden    http://tiswww.tis.cwru.edu/~chet/

reply via email to

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