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
}

Running the block labelled '1' prints "failed" and returns 1 as the exit code, while 
running the other block prints "test" and returns 0. However, the result should be the 
same.

It should not. The manual lists the instances where the shell does not
exit if a command fails while -e is enabled, and and-or lists are one of
those.

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


Reply via email to