Sources Bugzilla – Bug 10278
glob() gives inconsistent results with trailing "/"
Last modified: 2012-12-19 10:49:42 UTC
The POSIX spec doesn't specify exactly what should happen with a pattern ending in "/"; all it says about slashes in patterns is: The slash character in a pathname shall be explicitly matched by using one or more slashes in the pattern; it shall neither be matched by the asterisk or question-mark special characters nor by a bracket expression. All shells I'm aware of interpret this to mean that if your glob expression ends with a "/", it should match only directories. GNU glob() handles this correctly for simple globbing expressions like "*/", but for other expressions like "dir/*/", "/*/", etc. it returns all directories with a trailing slash, AND all files without a trailing slash. I believe this inconsistent behavior is a bug. See also GNU make bug #18123 http://savannah.gnu.org/bugs/index.php?18123
The rest of POSIX is pretty clear that pathname resolution of a name with a trailing slash can only succeed if it matches a directory; this is definitely a bug in glob().