The bug happens to me on
GNU bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu)
and
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.4.0)

The script is attached, but the function in question is this:

function debug1 {
    [ "$debug" ] && echo "$(date "+%Y-%m-%d %H:%M:%S"): $@"
}

If it is defined like this then no problem exists:

function debug1 {
    if [ "$debug" ]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): $@"
    fi
}

nor if it is defined like this:

function debug1 {
    [ "$debug" ] && echo "$(date "+%Y-%m-%d %H:%M:%S"): $@"
    :
}

When I run the script I see this output:

BEFORE test 2
AFTER test 2
BEFORE test 1

but I expected to see

BEFORE test 2
AFTER test 2
BEFORE test 1
AFTER test 1

It took me hours of work to distill this down from a very large and long
running script.

foo.sh is attached.

Attachment: foo.sh
Description: Bourne shell script

Reply via email to