Professional Web Applications Themes

rookie question: test -n not the opposite of test -z? - Linux / Unix Administration

On my linux fedora core 4 system, the man pages for test indicate the following: .... [-n] STRING the length of STRING is nonzero -z STRING the length of STRING is .... Which to me indicates that testing with -n should give the opposite result of -z. When executing the following code: [/ref][/ref] #!/bin/sh if ( test -z $FOO ) then echo test -z returns true else echo test -z returns false fi if ( test -n $FOO ) then echo test -n returns true else echo test -n returns false fi if ( test $FOO ) then echo test returns ...

  1. #1

    Default rookie question: test -n not the opposite of test -z?

    On my linux fedora core 4 system, the man pages for test indicate the
    following:
    ....
    [-n] STRING
    the length of STRING is nonzero

    -z STRING
    the length of STRING is
    ....

    Which to me indicates that testing with -n should give the opposite
    result of -z. When executing the following code: [/ref][/ref]
    #!/bin/sh

    if ( test -z $FOO ) then
    echo test -z returns true
    else
    echo test -z returns false
    fi

    if ( test -n $FOO ) then
    echo test -n returns true
    else
    echo test -n returns false
    fi

    if ( test $FOO ) then
    echo test returns true
    else
    echo test returns false
    fi

    <<<<<<<<<<<<<<<<<<
    I get the following result:

    test -z returns true
    test -n returns true
    test returns false

    Am I misunderstanding the man pages?

    Thanks

    ffarzaneh@gmail.com Guest

  2. #2

    Default Re: rookie question: test -n not the opposite of test -z?

    On Fri, 2006-01-20 at 15:20 -0800, com wrote: 
    [...]

    Try replacing the '()' with '[]'
    --
    S. Anthony Sequeira
    ++
    QOTD:
    "You want me to put *holes* in my ears and hang things from them?
    How... tribal."
    ++


    S. Guest

  3. #3

    Default Re: rookie question: test -n not the opposite of test -z?

    com wrote: [/ref]
    > #!/bin/sh
    >
    > if ( test -z $FOO ) then
    > echo test -z returns true
    > else
    > echo test -z returns false
    > fi
    >
    > if ( test -n $FOO ) then
    > echo test -n returns true
    > else
    > echo test -n returns false
    > fi
    >
    > if ( test $FOO ) then
    > echo test returns true
    > else
    > echo test returns false
    > fi
    >
    > <<<<<<<<<<<<<<<<<<
    > I get the following result:
    >
    > test -z returns true
    > test -n returns true
    > test returns false
    >
    > Am I misunderstanding the man pages?
    >
    > Thanks
    >[/ref]

    Drop the parenthesis. IIRC the parenthesis create a subshell. Also [
    is an alias for test, so you can do test -z ... or [ -z ... ]. Make
    sure you have a space after [ and before ].

    Jerry

    Jerry Guest

  4. #4

    Default Re: rookie question: test -n not the opposite of test -z?

    On 20 Jan 2006, in the Usenet newsgroup comp.unix.admin, in article
    <googlegroups.com>, com
    wrote:
     

    Doesn't it give examples?
     [/ref]
    >#!/bin/sh
    >
    >if ( test -z $FOO ) then[/ref]

    if ( test -z "$FOO" ) then

    Try that - also remember to assign a value to FOO.

    See

    31540 Jul 27 2000 Bash-Prog-Intro-HOWTO

    and

    http://tldp.org/LDP/abs/html/index.html

    Old guy
    Moe Guest

Similar Threads

  1. Can I use Application Center Test for web service stress test?
    By A.M-SG in forum ASP.NET Web Services
    Replies: 4
    Last Post: October 6th, 01:02 AM
  2. Rookie: HTML::TableExtract test will not print
    By sdfgsd in forum PERL Miscellaneous
    Replies: 3
    Last Post: October 9th, 03:31 PM
  3. Test::Unit non-auto-run test case?
    By Sean O'Dell in forum Ruby
    Replies: 1
    Last Post: September 18th, 06:19 PM
  4. Test::Unit -- multiple errors in test method ???
    By Johan Holmberg in forum Ruby
    Replies: 14
    Last Post: September 15th, 03:33 PM
  5. The server response was: 550 5.7.1 <testtest.com>... we do not relay
    By S. Justin Gengo in forum ASP.NET General
    Replies: 0
    Last Post: August 6th, 03:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139