help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] questions about errexit, pipes to while loops


From: Chet Ramey
Subject: Re: [Help-bash] questions about errexit, pipes to while loops
Date: Wed, 28 Mar 2012 11:40:55 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 3/27/12 1:41 PM, Jonathan Baccash wrote:
> Thanks  a bunch Chet. It sounds like the docs mixed with the bug on the first 
> example had me confused about what is considered a simple command. And it 
> sounds like newer versions of bash and posix are moving toward more sane 
> semantics (IMO), and I look forward to using bash 4.2. Perhaps it would be 
> good if the last example caused the compound command to return an error 
> status (and thereby fail the script when set -e is set)? Or perhaps there 
> needs to be an analogue of set -u for redirection to a file that doesn't 
> exist?

Posix actually speaks directly to what it calls `redirection errors':

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_01

They don't rise to the level that would cause the shell to exit, whether
or not -e is set, unless applied to one of the special builtins (and
never in an interactive shell).  The usual workaround

[ -f /file/you/want/there ] || exit 1
command using < /file/you/want/there

is the best.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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