How to check parameter variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check parameter variable?
# 1  
Old 06-10-2005
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
# 2  
Old 06-10-2005
Why don't you clarify "it did not work" and post the error you got?
# 3  
Old 06-10-2005
try ... in ksh ...

[ $email ] && do_something
# 4  
Old 06-10-2005
sorry for not being clear Smilie

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
# 5  
Old 06-10-2005
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 ....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identify the Parameter variable file

Hi I am trying to understand a shell scipt file ( .ksh file ) . In the shell script we are referring a variable . Example : SessLogs=$STAFF_MSTR_DIR/staff_dtls There are no references in the shell script from where the variable "$STAFF_MSTR_DIR" is being read from . Could anyone... (2 Replies)
Discussion started by: Sudheer Maddula
2 Replies

2. Shell Programming and Scripting

Duplicate check by passing external parameter

I have a code which is using to find duplicates in a files based on column.Below is the same code which is used to find duplicates in my file based on column 1 awk -F'|' '{if (x) { x_count++; print $0; if (x_count == 1) { print x } } x = $0}' FileName >Dup_File.txt But my requirement here is... (3 Replies)
Discussion started by: ginrkf
3 Replies

3. Shell Programming and Scripting

variable parameter assigning prblms

Hi, In my script, there is a variable as below TME=`date +%H` I want to take this TME value into another variable called TME_PAR which i can use outside of the current script and this TME_PAR is already present in my home_dir and i wrote below line of code $home_dir/$TME_PAR=`echo... (1 Reply)
Discussion started by: JSKOBS
1 Replies

4. Shell Programming and Scripting

Check parameter is number or string

Hey I'm new in linux, I'm looking for a code to check whether the parameter is a number or a string. I have already tried this code: eerste=$(echo $1 | grep "^*$">aux) if But it doesn't work.:confused: Thanks (2 Replies)
Discussion started by: Eclecticaa
2 Replies

5. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

6. Shell Programming and Scripting

Check input parameter

Hi all i need to check that if user has passed any input parameter while executing he shell script like ./test1.sh -a"-v" then do smothing if user execute the script without giving input paramater then ./test1.sh then do something how can we check this input parameter (6 Replies)
Discussion started by: aishsimplesweet
6 Replies

7. UNIX for Advanced & Expert Users

How to check what are the current kernel parameter settings

Hi all, I have four (4) different UNIX flavours and I want to know whether the following commands are correct with respect to wanting to check on what are my current kernel parameter settings. I just want to clear the doubts hanging over my head whether the commands below are the right ones... (2 Replies)
Discussion started by: newbie_01
2 Replies

8. Shell Programming and Scripting

Reading a variable from parameter file

HI all, I have a parameter file with entries like $$Name =Abhinav $$CUTOFF_DATE = 11/11/2209 I am reading a variable from this file using a awk command like : var2=`awk -F"" "/CUTOFF_DATE/{f=$1;}{print f;}" InputFIleName` but facing an error like awk: cmd. line:1:... (3 Replies)
Discussion started by: abhinav192
3 Replies

9. Shell Programming and Scripting

Check if parameter passes in contains certain string

Hi Guys, I am writing a Unix script which accepts a directory path as parameter $1 so something like /user5.data/WA/01 will be passed in. I want to determine if the directory path passed in contains "WA" as above (because then I need to do something specific if it does) What is the... (9 Replies)
Discussion started by: bcunney
9 Replies

10. Shell Programming and Scripting

Help with making a parameter check script.

I am making a script to check the parameters, but it seems that I can't catch the parameters by loop. $ cat sendmsg.sh #!/bin/sh ## Parameter Check i=0 max=$# while do PARAM=$${i} i=`expr ${i} + 1` echo ${PARAM} done How can I get the $1, $2, $3 by loop and set their... (2 Replies)
Discussion started by: GCTEII
2 Replies
Login or Register to Ask a Question