Test command with "-z" and "-n"

Hello all,

Please let me know, why the value of $? is diff for -z and -n. And explain what are the operends we can use with "test" and their purpose..

$ test -z ""
$ echo $?
0

$ test -n ""
$ echo $?
1

Thanx in advance..

Man Page for test (OpenSolaris Section 1) - The UNIX and Linux Forums

1 Like

man test

DESCRIPTION
The test utility evaluates the condition and indicates the
result of the evaluation by its exit status. An exit status
of zero indicates that the condition evaluated as true and
an exit status of 1 indicates that the condition evaluated
as false.

-n string True if the length of string is
non-zero.
-z string True if the length of string string
is zero.

hope you understand from the above man page contents

1 Like