Re: set -e not working as expected with conditional operators

2023-06-02 Thread Greg Wooledge
On Fri, Jun 02, 2023 at 09:01:11AM -0400, Chet Ramey wrote: > On 6/1/23 9:01 PM, rpaufin1 wrote: > > Consider the following script: > > > > #!/bin/bash > > > > f() { > > ls missing-file 2> /dev/null > > echo "test" > > } > > > > # 1 > > (set -e; f); ret=$? > > if (( ret )); the

Re: set -e not working as expected with conditional operators

2023-06-02 Thread Chet Ramey
On 6/1/23 9:01 PM, rpaufin1 wrote: Consider the following script: #!/bin/bash f() { ls missing-file 2> /dev/null echo "test" } # 1 (set -e; f); ret=$? if (( ret )); then echo "failed" exit 1 fi # 2 (set -e; f) || { echo "failed" exit 1 }

Re: set -e not working as expected with conditional operators

2023-06-02 Thread Robert Elz
Date:Fri, 02 Jun 2023 01:01:08 + From:rpaufin1 Message-ID: | What's going on here? I'm using the latest release, Bash 5.2.15. Bash is doing what it it is supposed to be doing. Just don't use -e unless you are an expert in what it actually means, and once yo

Re: set -e not working as expected with conditional operators

2023-06-02 Thread Oğuz İsmail Uysal
On 6/2/23 4:01 AM, rpaufin1 wrote: However, the result should be the same. The manual says otherwise: The shell does not exit if the command that fails is [...] part of any command executed in a && or || list except the command following the final && or ||

set -e not working as expected with conditional operators

2023-06-01 Thread rpaufin1
Consider the following script: #!/bin/bash f() { ls missing-file 2> /dev/null echo "test" } # 1 (set -e; f); ret=$? if (( ret )); then echo "failed" exit 1 fi # 2 (set -e; f) || { echo "failed" exit 1 } Running the block labelled '1' prints "fail