[CentOS] shell script strangeness...

Fri May 16 05:18:19 UTC 2008
Craig White <craigwhite at azapple.com>

On Fri, 2008-05-16 at 14:07 +0930, Ian Blackwell wrote:
> 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.
----
That works fine one CentOS 5 (double quotes and backtics) but not on
CentOS 4.6

Thanks...I guess it's good enough for now.

Craig