The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check if parameter passes in contains certain string bcunney Shell Programming and Scripting 9 08-15-2008 06:54 AM
awk: How do i check to see if a variable is a number? natdeamer Shell Programming and Scripting 1 09-06-2007 04:31 AM
Can a variable be used as a cut fieldname parameter? Knotty UNIX for Dummies Questions & Answers 3 03-31-2007 08:53 AM
Help with making a parameter check script. GCTEII Shell Programming and Scripting 2 03-07-2006 12:30 AM
Assign value to a variable in a parameter file gopskrish Shell Programming and Scripting 2 06-22-2005 04:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-10-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
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
Reply With Quote
Forum Sponsor
  #2  
Old 06-10-2005
Registered User
 

Join Date: May 2005
Posts: 40
Why don't you clarify "it did not work" and post the error you got?
Reply With Quote
  #3  
Old 06-10-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
try ... in ksh ...

[ $email ] && do_something
Reply With Quote
  #4  
Old 06-10-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
sorry for not being clear

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
Reply With Quote
  #5  
Old 06-10-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
in ksh ... this is the other form of the one i wrote earlier ...
Code:
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 ....
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0