Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • I have included only the ones special in all contexts (so that c acts the same as \c, c does not output c: command not found on STDERR, etc.) And I'm talking about sh here. Also, remember that this is a "clean-up" question, i.e. it's here to cover all such characters, so 19+ questions won't have to be asked. The question was posted thanks to an incident that different questions are asked for different such characters, we surely want to clean up here! Commented Jul 15, 2016 at 15:10
  • Well, ?[ are globbing operators, but isn't special in all contexts, but * seems to be, because echo * badly echoes the contents of the current directory (not escaping anything). echo ? echoes a literal ? and echo [ echoes a literal [. Also, ] is a globbing oberator too. Commented Jul 15, 2016 at 15:37
  • 1
    @ΈρικΚωνσταντόπουλος, * as a glob expands to all non-hidden files, ? to non-hidden single-character files, [a-z] to files whose name is a single character between a and z and so on. When they don't match any file (like in your case for ?), depending on the shell, you get a no-match error or the pattern expands to itself. In any case, even on shell where they expand to themselves, they need quoted in case they may match a file. Commented Jul 15, 2016 at 17:04
  • But, not as a glob, * still expands to something. Commented Jul 15, 2016 at 17:54
  • @ΈρικΚωνσταντόπουλος, * is like ?, if it doesn't match (for the case of * alone, that's when there are only hidden files in the current directory, for a* that's where there's no file whose name starts with a...), it either expands to itself (most Bourne-like shells), or raises a no-match error (csh, tcsh, fish (warning), zsh, bash -O failglob, early Unix shells), (or expands to nothing with the nullglob option of some shells or if there's another pattern that expands to something in csh, tcsh, zsh -o cshnullglob, early unix shells). Commented Jul 16, 2016 at 6:40