Wrong case behaviour?

The following case statement should not execute the "echo x" in my opinion, but it does. I'm pondering if this is a bug and I should send a bug report or not. Tested in fully patched bash version 4.4 and 5.0

case "1" in
    1) : ;;&
    2) : ;;
    *) echo x ;;
esac

The man page says:

1 Like

I see absolutely no inconsistency in the behavior of the case statement you have shown us with ;;& as the pattern list terminator for the pattern 1 when the string given to the case statement matches both the pattern 1 and the pattern * given the quote you have shown us from the (presumably bash ) man page.

2 Likes

But, following the man page, shouldn't the ;;& terminator test only the next pattern list 2) : ;; and not also *) echo x ;; ?

I find the wording in the man page you quoted ambiguous. The way you describe the code acting fits one of the possibilities of that ambiguous statement; and the way you expect it to behave fits another of the possibilities of that ambiguous statement.

I can't say that bash is behaving wrong from the quote you have shown us in the man page and I can't say that what you expected to happen is wrong. But, it appears that the way you want it to behave is not the way bash actually behaves.

I think it would be a good idea to post a bug report against the man page pointing out that the section you have quoted can be interpreted two ways and that bash does not behave the way you expected it to behave after reading the quoted text.

3 Likes

Ok, I'm going to send a bug report. Thank you very much!

Hi, elbrand
I do not see inconsistencies.

case "1" in
    1) echo 1;& #command in the next template even without a match
    2) echo 2;;& #next patten list comparison
    *) echo x
esac

But thanks a lot for the post. This is "case" behavior new to me.

1 Like

Here the response to my bug report:

So the behaviour is as intended. ;;& means: continue to look for a matching pattern.

5 Likes

Hi elbrand,
That was what I expected the response to be if you filed a bug report asking for the behavior of bash to change. That is why I suggested filing a bug report against the ambiguous wording in the man page. I agree that the way they describe the intended behavior is a mouthful. It will just be interesting to see what change they actually make to the man page to remove the ambiguity.

Please let us know if they tell you how the man page will actually be reworded to address your bug report.

Thank you for keeping us informed.