Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to run command whether $2 exist or not, help pls 1

Status
Not open for further replies.

adaaje

Technical User
May 26, 2006
60
AU
Hi guys, I've been struggling to create a script with condition whether $2 exist or not, so the logic is :

if $2 == ""
exit 1
if $2 == "email"
mail -s "test" ...
else
exit 1

how do I code it in ksh, I tried to code like above. But when I tried to execute the script, let's say the script name "check.ksh"

check.ksh 1 email --> it's running fine
check.ksh 1 -->

it said
./Check.ksh[48]: [: : unexpected operator/operand
./Check.ksh[48]: [: email: unexpected operator/operand

because I didn't put $2, how if I dont wanna put $2, but the script still running fine.

So the conclusion is
if I put $2 email --> email it
If I didn't put $2 --> don't do anything about command $2

Thx guys
 
Test [!]"[/!]$2[!]"[/!] instead of $2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
THX MATE, it's working... :)

have a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top