How to check parameter variable?

Hello All,

I have a script that will email out if the email address is specified as parameter 1.

I am using ksh, and then tried the following :

email=$1

Following did not work, I am getting error
test -z $email
test ${email:=" ") -eq " "
test -n $email
test ${?email}

What I am trying to do is, if $1 has a value, then email the report to that email address...

i.e. getreport.ksh test@gmail.com - will generate report and then email out.
getreport.ksh - will just generate the report

Thanks!

Joseph

Why don't you clarify "it did not work" and post the error you got?

try ... in ksh ...

[ $email ] && do_something

sorry for not being clear :slight_smile:

The error I am getting is :
./wms_chkorder.ksh[62]: test: argument expected

I tried using $# -gt 0 and it worked! But I am just wondering why $1 does not work......Even if my code work, how do I check if a parameter variable has a value?

thanks!

Joseph

in ksh ... this is the other form of the one i wrote earlier ...

if [ $myvar ]    ### this part here tests if the variable is set
then
   do_something
fi

... there are other ways variables are tested and set --- see man ksh --- but i don't think they are what you need based on my interpretation of your question

... also, make sure your $1 is not reset by succeeding lines in your script prior to it being used by the mail code ....