Skip to content

bug: set -e triggers on [[ ]] && cmd inside nested C-style for loops #867

@chaliy

Description

@chaliy

Problem

set -e incorrectly triggers on [[ ]] && cmd inside nested C-style for loops. Single for loops work correctly — only the nesting triggers the bug.

Reproduction

set -e
f() {
    for ((i=0; i<2; i++)); do
        for ((j=0; j<2; j++)); do
            [[ $i -ne $j ]] && echo "$i != $j"
        done
    done
    echo "done"
}
f

Real bash: prints 0 != 1, 1 != 0, done
Bashkit: exits after 0 != 1, 1 != 0 — when i=1,j=1 the [[ 1 -ne 1 ]] triggers set -e

Works correctly (single for loop):

set -e
f() {
    for ((i=0; i<2; i++)); do
        [[ $i -ne 0 ]] && echo "not zero"
    done
    echo "done"
}
f  # works — prints "not zero", "done"

Root cause

This is a variant of #807/#824. The fix for set -e + AND-OR lists works for single loops and functions, but not for nested C-style for loops. The nesting depth likely causes the AND-OR context flag to be lost.

Impact

The wedow/ticket cmd_link function uses this exact pattern — nested C-style for loops with [[ $i -ne $j ]] && others=... to build the list of other ticket IDs to link. This is the last bug preventing the full ticket script from running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions