Re: [expert] test command

2002-12-20 Thread ath1410
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??


On Thu, Dec 19, 2002 at 12:44:30PM +0900, ath1410 wrote:
 $test -z ""
this tests whether the string is empty. in this example it
is, therefor exit code 0.

 
 But it returns different value after followings.
 
 $test -n ""-- echo$? returns 1
 $test -n   --  "   " 0

this tests whether the string is NOT empty. the first one
is empty, so exit code is 1. the second one isn't empty.
i guess that you think that spaces count as empty strings,
but a space is a character as everyone (ascii 039), 
therefor your string isnt empty and exit code is 0.

okey?

have phun;)
miLosh


+-+ * Get your own Jmail account.|URL= http://www.jmail.co.jp
|--jmail--| * Get your own home page.|URL= http://www.servance.jp
+-+ * Get your own domain.|URL= http://domaintorou.com/


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] test command

2002-12-20 Thread jipe
On Fri, 20 Dec 2002 18:18:10 +0900
ath1410 [EMAIL PROTECTED] wrote:

 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??
 

this page can help you:
http://tldp.org/LDP/abs/html/testconstructs.html

bye
jipe


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] test command

2002-12-20 Thread milosh
On Fri, Dec 20, 2002 at 12:48:01PM +0100, jipe wrote:
 On Fri, 20 Dec 2002 18:18:10 +0900
 ath1410 [EMAIL PROTECTED] wrote:
  
  $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. 
  
oh, didn't saw that. ok. this' kinda twisted to understand. 
first of all, in the '-z' example u r giving a string, 
which means 'test' has something to test for. depending on
the argument, it returns its exit code.

the '-n' example u showed has NO argument, which means 'test'
has nothing to test for. it returns zero.

i understand ur confusion. it is common in programms to return 
a 0 value if a needed argument is missing. but this is 
not a programm, it's a shell builtin. end you do not got the
exit code from the command explizitly, but from that what
happend for the shell (namely bash, 4example).

so what happens for the shell? a 'strace test -n' reveals
here many secrets ;). the shell takes the command, validates
it, than takes the option, validates it. than nothing more is
to do. no more 'commands' r available to the shell. now here
plays strace. as u may see at the very end, it makes a close of
a library it opened befor to get ur locale. the close is 
successful, end THIS returns your exit (0).

clear now?

hope didn't confused u more, hehe.


 
 this page can help you:
 http://tldp.org/LDP/abs/html/testconstructs.html
nice site, but doesnt explain he's problem. at least i
didn't found an explanation there.

have phun ;)
miLosh

-- 
DONT ATTACK IRAQ !!!

this message was sent by:
+--+
|.::|[ The pleXus Network ]|::.|
+--+



msg63097/pgp0.pgp
Description: PGP signature


Re: [expert] test command

2002-12-20 Thread Dean S. Messing

 :: 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 -nspacesCR

or just

==test -nCR

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



Re: [expert] test command

2002-12-20 Thread ath1410
Tks Mr.miLosh  Mr.Dean,

This problem is getting clear now. However, let me please
ask one more question that still remains in me.

Mr.miLosh advised;

first of all, in the '-z' example u r giving a string, 
which means 'test' has something to test for. depending on
the argument, it returns its exit code.

No, in the '-z' example, I am NOT giveing a string.

   $test -zCR --  NOT $test -zspaceCR


Mr.Dean advised;

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".

Yes, I understand why $test -nCR returns 0. As you mentioned,
no argment is different from no string.

But this assumptions also apply '-z' option, isn't it? If so,
$test -zCR should return 1 not 0, because `test' should say
to itself (as in -z case) that I have no arg to test against,
then it should return authentic `false'. 

I read comments from Mr.miLosh  Mr.Dean many time and tried
test command in various patters many times. (I should have
studied English harder!!) And finally I came up with a
conclusion as Mr.which quotes;

'it is common in programms return a 0 value if a needed
argument is missing.' So test returns 0 if no arg is given
after -* option. Thus both $test -zCR and $test -nCR returns 0.

Now I forced myself to be clear on this!! But why $testCR
(no option, no args) returns 1 now, not 0!!

I agagin have to force myself into thinking that it's a rule.




+-+ * Get your own Jmail account.|URL= http://www.jmail.co.jp
|--jmail--| * Get your own home page.|URL= http://www.servance.jp
+-+ * Get your own domain.|URL= http://domaintorou.com/


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] test command

2002-12-19 Thread milosh
On Thu, Dec 19, 2002 at 12:44:30PM +0900, ath1410 wrote:
 $test -z 
this tests whether the string is empty. in this example it
is, therefor exit code 0.

 
 But it returns different value after followings.
 
 $test -n -- echo$? returns 1
 $test -n   --  0

this tests whether the string is NOT empty. the first one
is empty, so exit code is 1. the second one isn't empty.
i guess that you think that spaces count as empty strings,
but a space is a character as everyone (ascii 039), 
therefor your string isnt empty and exit code is 0.

okey?

have phun;)
miLosh

-- 
DONT ATTACK IRAQ !!!

this message was sent by:
+--+
|.::|[ The pleXus Network ]|::.|
+--+
www:plexus.shacknet.nu |
ftp:plexus.shacknet.nu +---+
irc:plexus.shacknet.nu:6667 channel: #nocturne |
+--+---+
pub  1024D/C944D699 miLosh (pleXus) [EMAIL PROTECTED] \_
Key fingerprint = 18FB 24BA 77A8 813F 6A8C  F67B C08C 5A76 C944 D699  \
+--+



msg63051/pgp0.pgp
Description: PGP signature


Re: [expert] test command

2002-12-19 Thread ath1410
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??


On Thu, Dec 19, 2002 at 12:44:30PM +0900, ath1410 wrote:
 $test -z ""
this tests whether the string is empty. in this example it
is, therefor exit code 0.

 
 But it returns different value after followings.
 
 $test -n ""-- echo$? returns 1
 $test -n   --  "   " 0

this tests whether the string is NOT empty. the first one
is empty, so exit code is 1. the second one isn't empty.
i guess that you think that spaces count as empty strings,
but a space is a character as everyone (ascii 039), 
therefor your string isnt empty and exit code is 0.

okey?

have phun;)
miLosh




+-+ * Get your own Jmail account.|URL= http://www.jmail.co.jp
|--jmail--| * Get your own home page.|URL= http://www.servance.jp
+-+ * Get your own domain.|URL= http://domaintorou.com/


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com