:: Tks for reply.
::
:: I understand the way $test -z "" returns 0 and $test -n "" returns 1.
::
:: What's puzzling me here is this.
::
:: $test -z (there is no space after -z, no argment) returns 0 which means
:: 'test command thinks no argment equals to the
:: empty string'.
::
:: However, $test -n (no space after, no argment) return 0 which
:: means 'test command in this case thinks no argment equals to
:: NO-empty string'.
::
:: When no argment is given, why test command thinks differenly
:: depending on the options -z and -n.
::
:: Can you help??
Maybe. What I'll say is based on years old knowledge so it may be
slightly off in the details (I hardly used `vargs' in my progamming
days) but the idea of what's happening will remain intact.
When, at the prompt (==>), you type something like:
==>command Arg1 Arg2
The shell first splits the line into strings arg0, arg1, arg2
and assigns the elements of the commandline to them:
arg0 = command
arg1 = Arg1
arg2 = Arg2
Whitespace, i.e., spaces, newlines, and tabs in between, before, and after
the elements on the commandline is (as I recall) discarded
so that if, say, Arg2 is not supplied, then string arg2 will not be
defined in the application you are running.
In particular, then, lets say you type:
==>test -n foo
Within `test' string arg1 = "-n" and string arg2 = "foo"
and the test is meaningful and will return TRUE
becuase `-n' says (is arg2 a sting) AND (is arg2 not empty)
which is true.
Likewise if arg2 = "" (the empty string) will return false.
However for
==>test -n<spaces><CR>
or just
==>test -n<CR>
where <spaces> stands for "spaces" and <CR> stands for the the newline,
arg2 is _undefined_ which means it is not even in the category of "string"
much less the empty string (which is still "something". namely \0 in memory).
So `test' is saying to itself "I have no arg2 to test against.
Formally,
arg2 does not exist ==> arg2 is not a string.
Hence you get an automatic "false". Likewise for -z and no
following argument.
Dean S. Messing
Display Algorithms & Visual Optimization Lab
Information Systems Technologies Dept.
Sharp Laboratories of America
Want to buy your Pack or Services from MandrakeSoft?
Go to http://www.mandrakestore.com