zsh-workers
 help / color / mirror / code / Atom feed
* About 'test' compatibility
@ 2002-02-26 20:07 DervishD
  2002-02-26 20:16 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: DervishD @ 2002-02-26 20:07 UTC (permalink / raw)
  To: Zsh

    Hello all :))

    This may be a stupid question. If so, please excuse me.

    I'm trying to use zsh for building the linux kernel, but the
configuration scripts make use of the '[' builtin, and assume that
'-a' means 'and', and not 'true if file exists'. The matter is that
the script is not using '[[', but just '['. The zsh.info file says
that '[' is included for compatibility and that it is just like the
system 'test'...

    What can I do for using zsh with the linux kernel (and not,
building a 'bash' just for it is not a solution ;)))).

    Thanks a lot :)
    Raúl


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 20:07 About 'test' compatibility DervishD
@ 2002-02-26 20:16 ` Bart Schaefer
  2002-02-26 20:28   ` DervishD
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2002-02-26 20:16 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh

On Tue, 26 Feb 2002, DervishD wrote:

>     I'm trying to use zsh for building the linux kernel, but the
> configuration scripts make use of the '[' builtin, and assume that
> '-a' means 'and', and not 'true if file exists'.

Can you give an example of the way this is failing?

Zsh 'test' does support -a for "and" but only when it appears as an infix
operator, e.g.

	[ foo -a bar ]		is true
	[ foo -a "" ]		is false
	[ "" -a bar ]		is false

	[ -a bar ]		is true if file "bar" exists, else false

My suspicion would be that the kernel build is doing something like

	[ $foo -a $bar ]

which zsh would interpret as infix -a only if $foo were non-empty.  The
correct test would be

	[ "$foo" -a "$bar" ]

and if that is indeed the issue, the kernel build scripts really should be
fixed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 20:16 ` Bart Schaefer
@ 2002-02-26 20:28   ` DervishD
  2002-02-26 21:33     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: DervishD @ 2002-02-26 20:28 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

    Hello Bart :))

    First, thanks for your answer: *real* fast ;))

>Can you give an example of the way this is failing?

    Yes, this is the line:

	if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
        do something
    else
        do another thing
    fi

    Well, when DEFAULT is '-d' and there is a third parameter (in
this case $3 has the value 'n') the 'something' is not done. The
'another thing' is done instead :??
 
>Zsh 'test' does support -a for "and" but only when it appears as an
>infix operator, e.g.

    Maybe the '-n' following '-a' is confusing zsh?

>which zsh would interpret as infix -a only if $foo were non-empty.  The
>correct test would be
>	[ "$foo" -a "$bar" ]

    This is the case. Maybe I'm missing something, I'm afraid.

    Thanks a lot for your answer, Bart.

    Raúl


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 20:28   ` DervishD
@ 2002-02-26 21:33     ` Bart Schaefer
  2002-02-26 21:39       ` DervishD
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2002-02-26 21:33 UTC (permalink / raw)
  To: DervishD; +Cc: zsh-workers

On Tue, 26 Feb 2002, DervishD wrote:

> >Can you give an example of the way this is failing?
>
> 	if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
>
>     Maybe the '-n' following '-a' is confusing zsh?

No, it's the -d in $DEFAULT that's confusing it.  When $DEFAULT is -d, zsh
is treating the above as "if there is a directory named `=' ..."

This should be written as

	if [ "x$DEFAULT" = "x-d" -a -n "$3" ]; then

or something similar.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 21:33     ` Bart Schaefer
@ 2002-02-26 21:39       ` DervishD
  2002-02-26 22:17         ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: DervishD @ 2002-02-26 21:39 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

    Hello Bart :)

>> >Can you give an example of the way this is failing?
>> 	if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
>>     Maybe the '-n' following '-a' is confusing zsh?
>No, it's the -d in $DEFAULT that's confusing it.  When $DEFAULT is
>-d, zsh is treating the above as "if there is a directory named `='
>..."

    Just curiosity: why BASH doesn't fail here too? The 'test'
builtin of the Bourne shell has the '-d' too.

>This should be written as
>	if [ "x$DEFAULT" = "x-d" -a -n "$3" ]; then
>or something similar.

    I'll notify the maintainer. Thanks for your help :)

    Raúl


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 21:39       ` DervishD
@ 2002-02-26 22:17         ` Bart Schaefer
  2002-02-27 10:36           ` DervishD
  2002-02-28  5:47           ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 2002-02-26 22:17 UTC (permalink / raw)
  To: DervishD; +Cc: zsh-workers

On Tue, 26 Feb 2002, DervishD wrote:

> >No, it's the -d in $DEFAULT that's confusing it.  When $DEFAULT is
> >-d, zsh is treating the above as "if there is a directory named `='
> >..."
>
>     Just curiosity: why BASH doesn't fail here too? The 'test'
> builtin of the Bourne shell has the '-d' too.

It appears that bash gives the infix '=' higher precedence than the prefix
'-d' or the infix '-a':

bash2-2.03$ mkdir '='
bash2-2.03$ if [ "-d" = ]; then echo There is a directory; fi
There is a directory
bash2-2.03$ if [ -d = -x ]; then echo There is a directory; fi
bash2-2.03$ if [ -d = -a x ]; then echo There is a directory; fi
[: too many arguments
bash2-2.03$ if [ -d . -a x ]; then echo There is a directory; fi
There is a directory

I haven't checked whether e.g. POSIX says anything about this.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 22:17         ` Bart Schaefer
@ 2002-02-27 10:36           ` DervishD
  2002-02-28  5:47           ` Bart Schaefer
  1 sibling, 0 replies; 8+ messages in thread
From: DervishD @ 2002-02-27 10:36 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

    Hi Bart :)

>>     Just curiosity: why BASH doesn't fail here too? The 'test'
>> builtin of the Bourne shell has the '-d' too.
>It appears that bash gives the infix '=' higher precedence than the prefix
>'-d' or the infix '-a':

    Yes, it's true. I think I definitely will notify the maintainer.

    Thanks again for all, Bart :)

    Raúl


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: About 'test' compatibility
  2002-02-26 22:17         ` Bart Schaefer
  2002-02-27 10:36           ` DervishD
@ 2002-02-28  5:47           ` Bart Schaefer
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2002-02-28  5:47 UTC (permalink / raw)
  To: zsh-workers; +Cc: DervishD

On Tue, 26 Feb 2002, Bart Schaefer wrote:

> > >No, it's the -d in $DEFAULT that's confusing it.  When $DEFAULT is
> > >-d, zsh is treating the above as "if there is a directory named `='
> > >..."
>
> It appears that bash gives the infix '=' higher precedence than the prefix
> '-d' or the infix '-a'

This really is a bug in zsh.  `[ -d = -d ]' is correctly parsed as an
infix `=' comparison, but `[ -d = -d anything ... ]' is not.

Does anybody know why the parser cares about !testargs[2] in the fragment
below?  Everything seems to work fine with it commented out.

Index: parse.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/parse.c,v
retrieving revision 1.11
diff -c -r1.11 parse.c
--- parse.c	2002/01/07 15:18:23	1.11
+++ parse.c	2002/02/28 05:40:49
@@ -1859,7 +1859,7 @@
 	    condlex();
 	    return par_cond_double(dupstring("-n"), s1);
 	}
-	if (testargs[1] && !testargs[2]) {
+	if (testargs[1] /* && !testargs[2] */) {
 	    /* three arguments: if the second argument is a binary operator, *
 	     * perform that binary test on the first and the trird argument  */
 	    if (!strcmp(*testargs, "=")  ||



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-02-28  5:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-26 20:07 About 'test' compatibility DervishD
2002-02-26 20:16 ` Bart Schaefer
2002-02-26 20:28   ` DervishD
2002-02-26 21:33     ` Bart Schaefer
2002-02-26 21:39       ` DervishD
2002-02-26 22:17         ` Bart Schaefer
2002-02-27 10:36           ` DervishD
2002-02-28  5:47           ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).