Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

If statement - How to write a null statement

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-16-2008   -   Original Discussion by april
april april is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 3 October 2010, 8:37 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands.

How do I write the "do nothing" statement in the following example?

Example:

if (( "$x"="1" && "$y"="a" && "$z"="happy" ))
then
do nothing
else
command
command
fi

Thanks.
Sponsored Links
    #2  
Old Unix and Linux 04-16-2008   -   Original Discussion by april
aigles's Unix or Linux Image
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Last Activity: 1 December 2014, 9:03 AM EST
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 62 Times in 58 Posts

Code:
if (( "$x"="1" && "$y"="a" && "$z"="happy" ))
then
   :
else
   command
   command
fi

Another way, invert your test :

Code:
if (( "$x"!="1" || "$y"!="a" || "$z"!="happy" ))
then
   command
   command
fi


Jean-Pierre.
Sponsored Links
    #3  
Old Unix and Linux 04-16-2008   -   Original Discussion by april
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 November 2017, 2:42 AM EST
Location: Foxborough, MA
Posts: 8,202
Thanks: 231
Thanked 785 Times in 732 Posts

Code:
if (( "$x"="1" && "$y"="a" && "$z"="happy" )); then
     :
else
   command
   command
fi

The Following User Says Thank You to vgersh99 For This Useful Post:
Bill L. (06-26-2013)
    #4  
Old Unix and Linux 04-16-2008   -   Original Discussion by april
april april is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 3 October 2010, 8:37 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks. That works.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If statement for null Jack_Maloney Shell Programming and Scripting 6 09-20-2011 01:16 PM
echo statement when find returns null tchoruma UNIX for Dummies Questions & Answers 2 09-24-2009 08:13 AM
write statement into one file rinku Shell Programming and Scripting 5 06-25-2007 06:03 AM
If statement falling over on a null record. Help please. TonyR Shell Programming and Scripting 3 04-29-2006 04:47 PM
How to write an OR statement aukequist Shell Programming and Scripting 1 11-08-2005 05:36 PM



All times are GMT -4. The time now is 04:59 AM.