posix me harder

Mike Gerdts Michael.Gerdts at alcatel.com
Thu Mar 14 23:40:53 EST 2002


On Thu, 2002-03-14 at 01:37, Martin Pool wrote:
> People might find this entertaining and/or useful:
> 
>   http://www.gnu.org/manual/autoconf-2.52/html_chapter/autoconf_10.html
> 
> With the help of Jos Backus I just discovered the answer to
> 
>   http://lists.samba.org/pipermail/rsync-cvs/2002-January/001271.html
> 
> is that Sun's test(1) is breathtakingly broken when passed a dangling
> symlink: 
> 
> $ ln -s /nowhere bad
> $ ls -l bad
> lrwxrwxrwx   1 josb     user            8 Mar 13 20:10 bad -> /nowhere
> $ if test -L bad; then echo bad; fi
> test: argument expected
> $ if test -h bad; then echo bad; fi
> bad
> $

This does not demonstrate that test(1) is broken.  First of all, pretty
much every shell these days has test as a builtin, and as such you
should be accusing sh(1), ksh(1), or similar.

With /bin/sh or /bin/ksh

    $ ls -l bad
    lrwxrwxrwx   1 mgerdts  foo            8 Mar 14 07:29 bad -> /nowhere
    $ /bin/test -L bad && echo bad
    bad
    $ if /bin/test -L bad ; then echo bad ; fi
    bad


With /bin/sh (SunOS 5.8 Generic 109324-02 February 2001):

    $ if [ -L bad ] ; then echo bad ; fi
    test: argument expected
    $ if test -L bad ; then echo bad ; fi
    test: argument expected
    
With /bin/ksh (SunOS 5.8 Generic 110662-04 May 2001)

    $ if [ -L bad ] ; then echo bad ; fi
    bad
    $ if test -L bad ; then echo bad ; fi
    bad
    
Note that /usr/xpg4/bin/sh is a symbolic link to /bin/ksh.

Mike





More information about the rsync mailing list