> ---------------------------------------------------------------------- > (0003970) joerg (reporter) - 2018-04-17 13:46 > http://austingroupbugs.net/view.php?id=985#c3970 > ---------------------------------------------------------------------- > In the Bourne Shell and in ksh88, the case statement first tries > to match the case argument against the pattern using gmatch() and > in case this does not result in a match, the quoting on the pattern > is removed and a plain string compare is done. > > In case if the example from the "Description", the case argument is > the C string "foo bar" and the pattern is the C string > "\\f\\o\\o\\ \\ \\b\\a\\r" that yields in the string: \f\o\o\ \ \b\a\r > > gmatch("foo bar", "\\f\\o\\o\\ \\ \\b\\a\\r") gives a match. > > If this did not result in a match, quotes in the pattern would be > removed and strcmp() called with the "case" argument and the pattern > with it's quoting removed. This results in a call to: > > strcmp("foo bar", "foo bar") that also gives a match.
I don't think bug 985 is the right place to raise this. If you want to pursue it please create a separate bug. Personally I am very strongly opposed to allowing this behaviour in the standard. It breaks applications which perform input validation such as: case $input in [0-9]) ;; *) echo "Input must be a single digit"; exit ;; esac This code is supposed only to allow the script to proceed when $input is a single digit, but with fall-back string matching it would proceed with input='[0-9]'. This behaviour is, frankly, utterly broken and I'm astonished that any shell author would think it was a good idea. -- Geoff Clare <[email protected]> The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England
