Hi,
Consider
pat="/de\v"
printf "%s\n" $pat
All shells appear to be in agreement that the backslash is taken
literally here. It's treated as quoted, even though $pat is unquoted.
Then,
case /dev in $pat) echo why ;; esac
Now, bash and dash say that the pattern does match -- they take the
backslash as unquoted, allowing it to escape the v. Most other shells
(bosh, ksh93, mksh, pdksh, posh, yash, zsh) still take the backslash as
quoted.
This doesn't make sense to me, and doesn't match historic practice: dash
before v0.5.5 took this backslash as quoted too. v0.5.5 then had some
other related bugs that were fixed in v0.5.6, but it looks like an
accident that this was not restored to the v0.5.4 behaviour.
This comes from expand.c's memtodest:
if ((quotes & QUOTES_ESC) &&
((syntax[c] == CCTL) ||
(((quotes & EXP_FULL) || syntax != BASESYNTAX) &&
syntax[c] == CBACK)))
USTPUTC(CTLESC, q);
This only escapes backslashes in field expansion context and in quoted
string context. Should this simply be
if ((quotes & QUOTES_ESC) &&
((syntax[c] == CCTL) || (syntax[c] == CBACK)))
USTPUTC(CTLESC, q);
or are there scenarios where it's important to treat an expanded
backslash as unquoted?
Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html