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


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-01-2008
Registered User
 
Join Date: Sep 2008
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
How to use "not equal to " in IF statement

Hi,
i need to compare two variables by using if statement
if [ $var1 -ne $var2 ]
then
echo "$var1"
else
echo "$var2"
fi

where -ne is used for not equal to but this is not working and giving me a syntax error. can anybody tel me how use not equal to with 'if' in ksh

thanks
Sponsored Links
    #2  
Old 10-01-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts

Code:
if [ $var1 != $var2 ] 
then 
echo "$var1"
else 
echo "$var2"
fi

Sponsored Links
    #3  
Old 10-01-2008
Registered User
 
Join Date: Sep 2008
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
thanks Ikon.... it's working fine now..
    #4  
Old 10-01-2008
yahyaaa's Avatar
Registered User
 
Join Date: May 2008
Location: Jordan
Posts: 107
Thanks: 2
Thanked 0 Times in 0 Posts
try to do it in KSH....

#!/bin/ksh
if [[ "$var1" -ne "$var2" ]] ; then

echo "$var1"

else

echo "$var2"

fi
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What is the meaning of "-s" option in "if" statement? rymnd_12345 UNIX for Dummies Questions & Answers 7 05-03-2012 12:22 PM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
What "-a" operator means in "if" statement aoussenko Shell Programming and Scripting 1 03-02-2011 10:30 AM
"if" and "then" statement is not working in RedHat Afi_Linux Red Hat 10 01-28-2011 03:26 AM



All times are GMT -4. The time now is 02:21 AM.