On Sat, 2011-08-20 at 09:02 -0400, Stephen Harris wrote:
On Sat, Aug 20, 2011 at 01:49:12PM +0100, Always Learning wrote:
On Sat, 2011-08-20 at 07:43 -0400, Robert Heller wrote:
(I did some magic with rpm -qa php* & sed to get the proper list of stuff to remove and then install.)
One does not require the ''
Yes you do. Especially if there are any files in the directory that would match php*. Basically the shell will attempt to do glob expansion on php* (so if you have php.ini and php.conf in the directory then it'll expand to those). Only if no files match will it leave the php* as php*.
So general good practice is to _always_ quote * (and ?) characters on command lines. You can either \ the character or put the whole thing inside '
eg rpm -qa 'php*' or rpm -qa php*
But rpm -qa php* is considered bad and _may_ break and should not be used. It's just bad practice.
Watch: $ ls $
So an empty directory. We'd expect the command to work... $ rpm -qa php* php-mbstring-5.1.6-27.el5_5.3 php-common-5.1.6-27.el5_5.3 php-cli-5.1.6-27.el5_5.3 php-5.1.6-27.el5_5.3
Yup! So far so good. Now let's create some random files... $ touch php.foobar php.ini php.baz $ rpm -qa php* $
Huh, no results. Let's debug... $ set -x $ rpm -qa php*
- rpm -qa php.baz php.foobar php.ini
$
You can see the shell has done what I described; php* has been expanded (since it's a file glob) to the files in the directory that matched
Quoting solves the problem: $ rpm -qa php*
- rpm -qa 'php*'
php-mbstring-5.1.6-27.el5_5.3 php-common-5.1.6-27.el5_5.3 php-cli-5.1.6-27.el5_5.3 php-5.1.6-27.el5_5.3
(Debug mode was still on, so you can see how the shell handled it).
Conclusion: when using * (or ?) on the command line, ALWAYS quote it to avoid unexpected side effects.
Thank you. I see the strange unexpected effect:
Server 6 : mkdir /example Server 6 : ls /example Server 6 : cd /example Server 6 : .l total 12 drwxr-xr-x 2 root root 4096 Aug 20 14:06 . drwxr-xr-x 24 root root 4096 Aug 20 14:06 .. Server 6 : Server 6 : Server 6 : touch php.foobar php.ini php.baz Server 6 : .l total 12 drwxr-xr-x 2 root root 4096 Aug 20 14:07 . drwxr-xr-x 24 root root 4096 Aug 20 14:06 .. -rw-r--r-- 1 root root 0 Aug 20 14:07 php.baz -rw-r--r-- 1 root root 0 Aug 20 14:07 php.foobar -rw-r--r-- 1 root root 0 Aug 20 14:07 php.ini Server 6 : ls php.baz php.foobar php.ini Server 6 : rpm -qa php* Server 6 : Server 6 : cd / Server 6 : rpm -qa php* php-pdo-5.1.6-27.el5_5.3 php-mbstring-5.1.6-27.el5_5.3 php-cli-5.1.6-27.el5_5.3 php-mcrypt-5.1.6-15.el5.centos.1 php-common-5.1.6-27.el5_5.3 php-mysql-5.1.6-27.el5_5.3 php-5.1.6-27.el5_5.3 phpmyadmin-2.11.11.3-2.el5.rf Server 6 :
Yes. Very unexpected results !
Thanks again.
Paul Always Learning.