Skip to content

Conversation

@dlmarion
Copy link
Contributor

No description provided.

@dlmarion dlmarion added this to the 4.0.0 milestone Jan 28, 2026
@dlmarion dlmarion self-assigned this Jan 28, 2026
Copy link
Contributor

@ddanielr ddanielr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is behaving as expected.

The exit code chaining is working off successful command exit codes.
Anything after && will run if all previous commands exit with a 0 return code.

So all of these lines will always trigger the "exit 1" condition on success.

I ran the following test in bash 4.2

First command succeeds

$: var=$(echo "foo" | grep "foo") || echo "failed grep" && echo "final action" 
final action

First command fails

$: var=$(echo "foo" | grep "bar") || echo "failed grep" && echo "final action" 
failed grep
final action

A simple exit function to wrap the two actions should give you the correct behavior

function fail_message() {
 echo "$1" && echo "exit 1"
}

$: var=$(echo "foo" | grep "foo") || fail_message "failed grep 1"                  
$: var=$(echo "foo" | grep "bar") || fail_message "failed grep 2" 

failed grep 2
exit 1

@dlmarion
Copy link
Contributor Author

Good info, I didn't think it behaved that way. It looks like just adding parentheses works too:

var=$(echo "foo" | grep "foo") || (echo "failed grep" && echo "final action")

var=$(echo "foo" | grep "bar") || (echo "failed grep" && echo "final action")
failed grep
final action

@dlmarion dlmarion merged commit 09624d5 into apache:main Jan 30, 2026
8 checks passed
@dlmarion dlmarion deleted the cluster-script-fix branch January 30, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants