On 22/06/2019 07:51, Stephane Chazelas wrote:
2019-06-21 23:58:32 +0100, Harald van Dijk:
In theory, pathname expansion is supposed to be done for every word, no
matter which characters it contains. Even in something as simple as

   echo hello

both words undergo pathname expansion. The first word is supposed to be
matched against the names in the current directory. If any matches "echo",
then pathname expansion produces that name. If none matches, then the "echo"
is used unmodified. Same for the second word.

Obviously, this means that pathname expansion produces "echo", regardless of
the contents of the current directory, and shells are allowed to bypass
reading the current directory as the results do not depend on it. This is
strictly speaking an optimisation though, and as such the "as the results to
not depend on it" is a requirement for the optimisation to be valid. If
shells bypass the reading when the results *do* depend on it, then that is a
bug in the shells.

That's your way to look at it.

That's the way it's specified in POSIX.

                               Obviously, all the shells that
implement a nullglob, failglob, nomatch, cshnulglob option or
have a FIGNORE/GLOBIGNORE variable (ksh, bash, zsh, yash at
least) don't see it that way, as that would mean that your

   echo hello

would only work when run in a directory that contains both files
(or at least one of them for cshnullglob, or at least if neither

For them, and me, and it seems Eric as well, globbing is an
operator that is invoked whenever a word contains an unquoted
wildcard character (in "list" contexts).

Shells can specify different behaviour so long as it produces the same results. bash, ksh and zsh do this by explicitly specifying that words are scanned for metacharacters and only looked for in the current directory if any metacharacters are found. Since this produces the same results as long as you do not set any non-standard options, that approach is perfectly valid.

yash documents that pathname expansion is done for each word, the same way POSIX does. As you would expect, when actually trying it, under shopt -s nullglob, echo hello still works as expected and prints "hello". Since yash does not match its own documentation, I would consider that a documentation bug in yash.

The rest of your message goes back to whether \ should function as an escape character, which is something I tried to avoid in this message, as it is not directly relevant to the point I was making.

Harald van Dijk

Reply via email to