Regarding test command


1. If a variable is undefined how do i check the variable undefined using test command?

echo $zzz
ksh: zzz: parameter not set

test $zzz
ksh: zzz: parameter not set
echo $?
-1

test -z $zzz
ksh: zzz: parameter not set
echo $?
-1


2. there is a option -z in test command which say true if the string has zero length. I had tried but i am not
getting the output
zzz=''
test -z $zzz
ksh: test: argument expected
zzz=""
test -z $zzz
ksh: test: argument expected
zzz=
test -z $zzz
ksh: test: argument expected
pigeon5566Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TalmashCommented:
man test

if condition  ;  then  action  ;  else  action2  ;  fi

you need the "else" action2, or add "!" before condition

example

if (!test $zzz) ....
manav_mathurCommented:
try
test -z "$zzz"

$zzz=''
test -z $zzz

In this, $zzz is an empty string, hence the test statement evaluates to
test -z

which is wrong for a zero length string, however
test -z ""
is correct which is obtained thru
test -z "$zzz"

Note : see usage of [ ] for emulating test.

manav_mathurCommented:
for 1) there's a hack

$abc=${zzz:='undefined'}
if [ $abc = 'undefined' ]; then
...
ahoffmannCommented:
1. not possible in ksh or with test
  use csh $?zzz
  in ksh, test, bash you only can check for an empty value which can not be distinguished from a none-existing variable

2 test -z "$zzz"   (as already said)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pigeon5566Author Commented:
Thanks a lot for the info
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.