![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| If Statement Problem.. | LinuxRacr | Shell Programming and Scripting | 2 | 02-26-2008 09:47 PM |
| problem with if statement equality | cleansing_flame | Shell Programming and Scripting | 1 | 02-12-2008 07:57 AM |
| Case statement problem | gzs553 | UNIX for Advanced & Expert Users | 6 | 11-14-2006 01:24 PM |
| if statement problem | djt0506 | UNIX for Dummies Questions & Answers | 4 | 12-04-2005 05:16 PM |
| if statement problem | coughlin74 | UNIX for Dummies Questions & Answers | 1 | 09-27-2001 01:31 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |