0

Ran into some strange behavior today. Wondering if anyone here can tell me what is behaving differently. Environment is a RHEL 6.7 server.

I run the following command:

yum list installed *mysql*

If my cwd is / or a number of other places I get the following output:

Installed Packages MySQL-client-advanced.x86_64 5.6.27-1.el6 @/MySQL-client-advanced-5.6.27-1.el6.x86_64 MySQL-server-advanced.x86_64 5.6.27-1.el6 @/MySQL-server-advanced-5.6.27-1.el6.x86_64 MySQL-shared-advanced.x86_64 5.6.27-1.el6 @/MySQL-shared-advanced-5.6.27-1.el6.x86_64 MySQL-shared-compat-advanced.x86_64 5.6.27-1.el6 @/MySQL-shared-compat-advanced-5.6.27-1.el6.x86_64

In a few other folders (including /opt on this server) I run the same command and get this output:

Error: No matching Packages to list

Now I know that I usually need to escape the wildcard in this command. If I run it as:

yum list installed \*mysql\*

then I get the correct output in both locations. I gather this is because of how bash globs wildcards. What I really want to know right now is why it globs it in one folder but doesn't in the other. I'm running both as root, printenv shows identical output (other than PWD), literally the only thing that changes between running the command both times is cd /opt

Can anyone tell me why this is happening or what things to look at to see why it might be different? TIA

Joe
  • 1,043
  • 8
  • 11

1 Answers1

5

This is because the result of the *mysql* globbing depends on the content of the directory you are in. Your shell interprets the * character (unless you escape it or hide it in quotes) by trying to match it to file names in the directory.

To illustrate, execute (in each of the directories in question)

echo yum list installed '*mysql*'
echo yum list installed *mysql*
ls -ld *mysql*
Law29
  • 3,557
  • 1
  • 16
  • 28
  • You are a genius. Thanks for pointing it out. In every folder that has something named `*mysql*` in it, the yum command fails. – Joe May 13 '16 at 21:11
  • Several months of classes followed by twenty years of experience make the most "genius" things seem simple :) – Law29 May 13 '16 at 23:33