bug-bash
[Top][All Lists]
Advanced

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

Re: Can't test "-l"


From: Chet Ramey
Subject: Re: Can't test "-l"
Date: Fri, 15 Dec 2000 11:14:34 -0500

> Bash Version: 1.14
> Patch Level: 7
> 
> Description:
>         [Detailed description of the problem, suggestion, or complaint.]
> 
> $ if [ "-l" != "-a" ] ; then echo "ok" ; fi
> [: -a: binary operator expected                <----- ?
> 
> $ aa='-l'
> $ if [ $aa != "-k" ] ; then echo "ok" ; fi
> [: -k: binary operator expected                <----- ?

Here's the relevant item from the bash-2.05 COMPAT file:

15.  Bash versions up to 1.14.7 included an undocumented `-l' operator to
     the `test/[' builtin.  It was a unary operator that expanded to the
     length of its string argument.  This let you do things like

        test -l $variable -lt 20

     for example.

     This was included for backwards compatibility with old versions of the
     Bourne shell, which did not provide an easy way to obtain the length of
     the value of a shell variable.

     This operator is not part of the POSIX standard, because one can (and
     should) use ${#variable} to get the length of a variable's value.
     Bash-2.x does not support it.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]