# Wrong case behaviour?

**URL:** <https://community.unix.com/t/wrong-case-behaviour/374666>\
**Category:** Shell Programming and Scripting\
**Created:** [January 25, 2019, 10:51pm UTC](https://community.unix.com/t/wrong-case-behaviour/374666 "2019-01-25T22:51:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elbrand](https://community.unix.com/letter_avatar/elbrand/32/6_449c533f586939b6e5f246632a46421f.png) [@elbrand](https://community.unix.com/u/elbrand)\
**Post date:** [January 25, 2019, 10:51pm UTC](https://community.unix.com/t/wrong-case-behaviour/374666/1 "2019-01-25T22:51:09Z")

</div>

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

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

```

The man page says:

> [@](#):
>
> ...  
> case word in [[(] pattern [| pattern] ... ) list ;; ] ... esac  
> ...  
> If the ;; operator is used, no subsequent matches are attempted after  
> the first pattern match. Using ;& in place of ;; causes execution to continue with  
> the list associated with the next set of patterns. Using ;;& in place of ;; causes  
> the shell to test the next pattern list in the statement, if any, and execute any  
> associated list on a successful match.  
> ...

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [January 25, 2019, 11:41pm UTC](https://community.unix.com/t/wrong-case-behaviour/374666/2 "2019-01-25T23:41:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elbrand](https://community.unix.com/letter_avatar/elbrand/32/6_449c533f586939b6e5f246632a46421f.png) [@elbrand](https://community.unix.com/u/elbrand)\
**Post date:** [January 25, 2019, 11:51pm UTC](https://community.unix.com/t/wrong-case-behaviour/374666/3 "2019-01-25T23:51:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [January 26, 2019, 12:05am UTC](https://community.unix.com/t/wrong-case-behaviour/374666/4 "2019-01-26T00:05:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elbrand](https://community.unix.com/letter_avatar/elbrand/32/6_449c533f586939b6e5f246632a46421f.png) [@elbrand](https://community.unix.com/u/elbrand)\
**Post date:** [January 26, 2019, 12:15am UTC](https://community.unix.com/t/wrong-case-behaviour/374666/5 "2019-01-26T00:15:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nezabudka](https://community.unix.com/letter_avatar/nezabudka/32/6_449c533f586939b6e5f246632a46421f.png) [@nezabudka](https://community.unix.com/u/nezabudka)\
**Post date:** [January 26, 2019, 3:45am UTC](https://community.unix.com/t/wrong-case-behaviour/374666/7 "2019-01-26T03:45:01Z")

</div>

Hi, elbrand  
I do not see inconsistencies.

```nohighlight
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.

---

<div class="post-metadata">

**Author:** ![elbrand](https://community.unix.com/letter_avatar/elbrand/32/6_449c533f586939b6e5f246632a46421f.png) [@elbrand](https://community.unix.com/u/elbrand)\
**Post date:** [January 27, 2019, 6:38am UTC](https://community.unix.com/t/wrong-case-behaviour/374666/8 "2019-01-27T06:38:37Z")

</div>

Here the response to my bug report:

> [@](#):
>
> Badly worded manual. What it means is "pretend this match didn't happen,  
> even though the command list has been executed, and continue scanning  
> the patterns in the case statement looking for another match, then do its  
> list, and after that, whatever its terminating operator says to do". But that  
> is quite a mouthfull ...

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

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [January 27, 2019, 11:19am UTC](https://community.unix.com/t/wrong-case-behaviour/374666/9 "2019-01-27T11:19:04Z")

</div>

> [@elbrand](#):
>
> Here the response to my bug report:
> 
> > [@](#):
> >
> > ...
> 
> So the behaviour is as intended. `;;&` means: continue to look for a matching pattern.

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.
