On Mon, 23 Jun 2025 at 19:02, Takaaki Konno <re_...@yahoo.co.jp> wrote:
> > x=abc > case def in > "${x#abc}"def) ;; > "${x##abc}"def) ;; > "${x%abc}"def) ;; > "${x%%abc}"def) ;; > "${x/abc/}"def) ;; > "${x//abc/}"def) ;; > "${x/#abc/}"def) ;; > "${x/%abc/}"def) ;; > *) echo 'not matched' > esac > # => not matched > Curiously, variations of this issue have existed for a VERY long time, since bash-3.00.0(92)-release (commit b80f6443b6b7b620c7272664c66ecb0b120a0998). At that stage only these forms were affected: x=def case abc in > "${x::0}"abc) ;; > "${x:1:0}"abc) ;; > *) echo FAILED ;; > esac > This got worse in 3.00.16(91)-release (commit eb87367179effbe5f430236db8259006d71438b7) where these also failed: x=def case abc in > "${x:3}"abc) ;; > *) echo FAILED ;; > esac In bash-3.1-rc2 (commit 28089d04354f1834f109bcb4730c9200234861bc) it just got weird: when quoted "${x:3}" started expanding to a DEL (\x7f) byte (but the ${x:1:0} expansion did not, though the case match still failed). This was also present in the master branch at bash-3.2.0(85)-beta (commit e7f1978acfd2125b69bca36994882a1333607739). It seemed to be fixed in bash-3.2.0(83)-release (commit 0628567a28f3510f506ae46cb9b24b73a6d2dc5d) But then it gets worse, in bash-4.0.0p1-alpha (commit f2f9854dfd1a35d3b2b10d5b59b96e951a45c3fe), where in addition all pattern-matching expansions are broken (but without resulting in apparent DEL bytes). x=def > case abc in > "${x#def}"abc) ;; > "${x%def}"abc) ;; > "${x/def}"abc) ;; > "${x/#def}"abc) ;; > "${x/%def}"abc) ;; > *) echo FAILED ;; > esac Since then the mismatch problem seems to have remained unchanged. The problem does not occur if there is anything else inside the quotes with the expansion, like x=def > case abc in > "${x#def}abc") echo SUCCESS ;; > esac or if the expansion is unquoted (as noted by Konno-san), like x=def > case abc in > ${x#def}abc) echo SUCCESS ;; > esac -Martin PS: I suspect the DEL bytes are somehow still present when expanding a variable with a modifier within a case pattern, but not when the same thing is expanded elsewhere.