bug-bash
[Top][All Lists]
Advanced

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

Re: "trap" output from "if" statement redirected wrongly


From: Chet Ramey
Subject: Re: "trap" output from "if" statement redirected wrongly
Date: Thu, 14 Apr 2022 11:39:46 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.8.0

On 4/13/22 8:58 AM, Frank Heckenbach wrote:

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:

This script writes "foo" to bar rather than stdout as I'd expect.

That's not unreasonable, but it's not how it works.

It's triggered by the "if" statement (which doesn't even cause
running in a subshell, so it's not that).

The entire `if' statement executes with its stdout redirected. That means
the `false' that causes the shell to exit immediately has its stdout
redirected, which the exit trap inherits.

Most shells behave like bash does here; dash is a notable exception.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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