bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible bug in bash


From: flyingrhino
Subject: Possible bug in bash
Date: Fri, 13 May 2022 15:34:49 +1200
User-agent: Orcon Webmail

Hi,

Should the "else" condition after the: || run if the last command in the: && section exits non zero?

I tested it this way:

Script:


#!/bin/bash

[[ "a" == "a" ]] && \
    {
    echo "equal"
    ls x
    } || {
    echo "***** SHOULD NOT DISPLAY 4"
    }


Result:

./moo.sh
equal
ls: cannot access 'x': No such file or directory
***** SHOULD NOT DISPLAY 4



2022-05-13 15:33:25 ken@asus303 /tmp/ $ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)



BTW, I've checked other conditions as follows and they look ok:

2022-05-13 15:32:55 ken@asus303 /tmp/ $ cat moo.sh
#!/bin/bash

[[ "a" == "a" ]] && \
    {
    echo "equal"
    ls x
    } || {
    echo "***** SHOULD NOT DISPLAY 4"
    }

echo "================================"


[[ "a" == "a" ]] && \
    {
    echo "equal"
    } || {
    echo "***** SHOULD NOT DISPLAY 1"
    }

echo "================================"

[[ "a" == "a" ]] && \
    {
    echo "equal"
    ls x
    :
    } || {
    echo "***** SHOULD NOT DISPLAY 2"
    }

echo "================================"

[[ "a" == "a" ]] && \
    {
    echo "equal"
    ls x || :
    } || {
    echo "***** SHOULD NOT DISPLAY 3"
    }

echo "================================"

[[ "a" == "b" ]] && \
    {
    echo "equal"
    } || {
    echo "NOT EQUAL"
    }

2022-05-13 15:32:59 ken@asus303 /tmp/ $






reply via email to

[Prev in Thread] Current Thread [Next in Thread]