Re: shell script strangeness...

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



On Fri, 2008-05-16 at 17:03 +0930, Ian Blackwell wrote:
> Craig White wrote:
> > 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
> >
> > _______________________________________________
> > CentOS mailing list
> > CentOS@xxxxxxxxxx
> > http://lists.centos.org/mailman/listinfo/centos
> >
> >   
> I can only imagine it is "working" in 4.6 because the result of "grep 
> entry_chooser.js /var/log/httpd/access_log" is either empty or 1 
> "word".  The test syntax [ -z xxx ] would report the "too many 
> arguments" error whenever the grep returned more than one word.  You can 
> test this at your command line by typing in:-
>     [ -z one ]
> and
>     [ -z one two three four five ]
> 
> The first will return "false" but you'll just see another bash prompt, 
> the second will report the "too many arguments" error.  This is 
> certainly the case for me using RHEL4.6, so I would imagine CentOS4.6 
> should be the same.  You can also see it explained by these commands and 
> results:-
> [irb@zaphod ~]$ [ -z ]
> [irb@zaphod ~]$ echo $?
> 0
> [irb@zaphod ~]$ [ -z one ]
> [irb@zaphod ~]$ echo $?
> 1
> [irb@zaphod ~]$[ -z one two three four ]
> -bash: [: too many arguments
> [irb@zaphod ~]$ echo $?
> 2
> [irb@zaphod ~]$
> 
> I hope this helps you understand why it is "working" on one machine but 
> not another.
> 
> Ian
> 
> PS: I always prefer $(cmd) to backtics for readability.  e.g.
> 
> if [ -z "$(grep entry_chooser.js /var/log/httpd/access_log)" ]
> 
> PPS: grep -q works for me on RHEL4.6 and CentOS5.1
----
makes a lot of sense - 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