[CentOS] shell script strangeness...

Fri May 16 04:37:10 UTC 2008
Ian Blackwell <ian at ikel.id.au>

Craig White wrote:
> On my CentOS 4.6 server, this works...
> if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
> On my CentOS 5.1 server, this gives me the following error...
> ./test_file.scr: line 3: [: too many arguments
> Can anyone explain why the difference and suggest something that makes
> both cases happy?
> Thanks
> Craig
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
Not sure why 4.6 is allowing it, but your if test will be resolving to 
something like this:-
if [ -z this line from your log file and another line and even more 
lines until your if test fails with too many arguments I hope you don't 
want me to keep typing to make the point ]

To fix it, wrap the grep instead double quotes as well as the ticks - e.g.
if [ -z "`grep entry_chooser.js /var/log/httpd/access_log`" ]
Then the output from the grep will be seen as one long string, not a 
multitude of words from your log file.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3617 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.centos.org/pipermail/centos/attachments/20080516/7d6ecfea/attachment-0005.bin>