0

Having read apt-get remove with wildcard removed way more than expected. why? (after making a similar mistake myself), I am significantly more cautious about using * in commands with which I am not completely familiar.

Clearly

sudo apt-get remove k3b*

does not do what the user intended, and I find myself really wanting to know: what other commands will not behave as some users may intend when using a wild card?

cmhughes
  • 141

1 Answers1

3

From the bash manual:

Pathname Expansion: After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern. If no matching file names are found, and the shell option nullglob is not enabled, the word is left unchanged.

So, bash will usually try to do pathname expansion (using the files in the current directory, in the apt-get example you used), and if that fails the word will be passed to the application.

If you aren't intending to be using shell globs for pathname expansion, then expect the application to interpret your wildcard at will, and the behavior you can expect will depend on the application.

If you are unsure, I would strongly recommend reading the command's manual before passing it wildcards.

jkt123
  • 3,530
  • 22
  • 24