Re: shell script strangeness...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Thu, 2008-05-15 at 22:00 -0700, Garrick Staples wrote:
> On Fri, May 16, 2008 at 02:07:10PM +0930, Ian Blackwell alleged:
> > 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?
> > >

> > 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.
> 
> Even better is to use 'grep -q' to avoid possibly large string expansions...
>    if grep -q entry_chooser.js /var/log/httpd/access_log ;then
----
for this purpose, -q didn't seem to matter much - thanks

Craig

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux