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
If Statement Problem.. LinuxRacr Shell Programming and Scripting 2 02-26-2008 08:47 PM
problem with if statement equality cleansing_flame Shell Programming and Scripting 1 02-12-2008 06:57 AM
Case statement problem gzs553 UNIX for Advanced & Expert Users 6 11-14-2006 12:24 PM
if statement problem djt0506 UNIX for Dummies Questions & Answers 4 12-04-2005 04:16 PM
if statement problem coughlin74 UNIX for Dummies Questions & Answers 1 09-27-2001 01:31 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2003
Registered User
 

Join Date: Mar 2002
Posts: 170
Stumble this Post!
problem with an IF statement

I need an IF statement that will compare the contents of the variable CX with the actual string "CP". ie. If the contents of $CX are NOT equal to the actual string "CP" then blah blah blah.

I have tried a number of things including the following.......


if [[ $CX != `echo CP` ]]; then

if [[ $CX != "CP" ]]; then

if [[ $CX != CP ]]; then


none of which seem to work

any suggestions ?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-17-2003
oombera's Avatar
Have a day :|
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Stumble this Post!
Which shell are you using?

Try using one set of brackets instead of two. All the ways you listed work fine in ksh...

CX="CR"

if [[ $CX != "CP" ]]; then
echo "not equal"
fi

if [ $CX != "CP" ]; then
echo "not equal"
fi
Reply With Quote
  #3 (permalink)  
Old 04-17-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,425
Stumble this Post!
I would expect all 3 of your if statements to work in ksh although the first one is a poor choice.

My guess is that you have mis-diagnosed your problem. The if statements are working but the contents of your variable is not what you think.

Could the variable contain white space or unprintable characters? Put these in front of your if statement....

echo CX is ${#CX} characters in length
echo CX = $CX
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:40 PM.


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

Content Relevant URLs by vBSEO 3.2.0