2019-06-15 00:44:02 +0700, Robert Elz:
[...]
> V='\.'
>
> case "$word" in
> \\$V) printf %s\\n "match: ${word}";;
> *) printf %s\\n "no match: ${word}";;
> esac
[...]
> context like a here doc, or uselesslly, arithmetic) in which case it is
> like everything else that has been quoted, a literal char, or if the
> expansion was unquoted, the \ is then a pattern quoting char (and there
> needs to be 2 of them to get a literal \ in the pattern that way).
[...]
And again, there is no such thing as a "pattern quoting char" in
most sh implementations including ksh88 (and all its
predecessors, Bourne, Mashey, Thomson), Forsyth shell, pdksh and
all its derivatives (mksh, openbsd sh), the Almquist shell and
many of its descendants including as mentioned earlier the sh of
NetBSD 7.1.2, yash and zsh at least (at least the versions I
tested).
In all those, the code above matches on \\. and not \. as \
doesn't have a special meaning as a wildcard operator, only as a
quoting operator.
Again the portable way for a pattern stored in a variable to
match on something that starts with \ is:
pattern='[\\]*'
To match on something that starts with *
pattern='[*]*'
Insisting that it should be
pattern='\\*'
and
pattern='\**'
will need all those shells to be changed first, and you won't be
able to so that in at least 10 years.
--
Stephane