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
comparing 2 strings satish@123 Shell Programming and Scripting 2 05-16-2008 04:59 AM
comparing strings agarwal Shell Programming and Scripting 3 04-16-2008 02:29 AM
Urgent:Comparing two Strings using If Loop Anji Shell Programming and Scripting 2 01-09-2008 04:54 AM
Comparing Two Strings Anji Shell Programming and Scripting 8 01-09-2008 02:32 AM
Comparing strings yakyaj UNIX for Advanced & Expert Users 2 03-22-2007 09:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-20-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
comparing two strings

Hi

How do i compare two strings in shell script. Below is an example but I am not getting the desired output, plz help

Code:
if [ $Name = 'Ragha' AND $Status = 'Active' ]
then
echo success
fi
I am not getting the desired output if I do this. plz help
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-20-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
doing 'man test' yields the following:
Code:
          condition1 -a condition2
                True if both condition1 and condition2 are  true.
                The -a binary primary is left associative and has
                higher precedence than the -o binary primary.

          condition1 -o condition2
                True if either condition1 or condition2 is  true.
                The -o binary primary is left associative.
Reply With Quote
  #3 (permalink)  
Old 09-20-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
hi

what if I have a condition like this

Code:
if [ $Name = 'Ragha%' -a  $Status = 'Active%' ]
then
echo success
fi
I am not getting the result in this case
Reply With Quote
  #4 (permalink)  
Old 09-20-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
what are the values of '$Name' and '$Status' ?
can you can the script with the 'set -x' option and provide the output?
Reply With Quote
  #5 (permalink)  
Old 09-20-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
Hi vgersh..

The problem is actually with the loop. The condition is working fine. In this code when the condition satisifies it has to give output an output like this

sble01
ALLTEL - WebOrders WorkMon Shutting
down
success

sble01
ALLTEL WorkMon24Hrs
Running

but it is giving output as below
sble01
ALLTEL - WebOrders WorkMon Shutting
down
success

success <----------------This shouldnt appear here
sble01
ALLTEL WorkMon24Hrs
Running


pls see the code and find out the error

Code:
until [ $i -eq ${#wfname[*]} ]
do
      
$SIEBEL_ROOT/bin/srvrmgr -g $SIEBEL_GATEWAY -e $SIEBEL_ENTERPRISE -s $SIEBEL_SERVER -u n9912499 -p n9912499 -c "list component '${wfname[$i]}' show SV_NAME, CC_NAME, CP_DISP_RUN_STATE" -o "$temp_output"  
sed -n "/^SV_NAME/,$ p" < $temp_output | sed "/rows* returned/,$ d" | awk '
NR > 2 {n = split($0,arr," ")
printf("%s|",arr[1])
for( k = 2; k <=n-1;++k) printf("%s ",arr[k])
printf("\b|%s\n",arr[n]) }' > temp
old_IFS=$IFS
IFS="|"
while read SV_NAME CC_NAME CP_DISP_RUN_STATE
do
echo $SV_NAME
echo $CC_NAME
echo $CP_DISP_RUN_STATE

if [ "${wfname[$i]}" != "ALLTEL - WebOrders WorkActn" ]
then
if [ "$CP_DISP_RUN_STATE" != "${status[0]}" ]
then
echo success
fi
elif [ "${wfname[$i]}" = "ALLTEL - WebOrders WorkActn" ] 
then
if [ "$CP_DISP_RUN_STATE" != "${status[1]}" ]
then
echo good
fi
fi
done < temp
((i=i+1))
done
thanks a lot
Reply With Quote
  #6 (permalink)  
Old 09-20-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
I really don't have much time to debug tthis, but you could start [as suggested] by putting the 'set -x' at the top of your script and see what gets executed and how things get 'compared'.

Good luck.
Reply With Quote
  #7 (permalink)  
Old 09-20-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
i did a set -x.. this is the output I get

Code:
 + read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ echo sble01
sble01
+ echo ALLTEL - WebOrders WorkMon Shutting
ALLTEL - WebOrders WorkMon Shutting
+ echo down
down
+ [ ALLTEL - WebOrders WorkMon != ALLTEL - WebOrders WorkActn ]
+ [ down != Running ]
+ echo success
success
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ echo

+ echo
+ echo

+ [ ALLTEL - WebOrders WorkMon != ALLTEL - WebOrders WorkActn ]
+ [  != Running ]
+ echo success
success
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ (( i=i+1 ))
+ [ 1 -eq 2 ]
+ /siebel/sble01/siebsrvr/bin/srvrmgr -g lfs6217q.alltel.com -e esble -s sble01 -u n9912499 -p n9912499 -c list component 'ALLTEL WorkMon24Hrs' show SV_NAME, CC_NAME, CP_DISP_RUN_STATE -o /siebel/sble01/siebfile/batch//WorkflowMon/log/temp_20060920_170358.out
+ sed -n /^SV_NAME/,$ p
+ 0< /siebel/sble01/siebfile/batch//WorkflowMon/log/temp_20060920_170358.out
+ sed /rows* returned/,$ d
+ awk
NR > 2 {n = split($0,arr," ")
printf("%s|",arr[1])
for( k = 2; k <=n-1;++k) printf("%s ",arr[k])
printf("\b|%s\n",arr[n]) }
+ 1> temp
+ old_IFS=|
+ IFS=|
+ set -x
+ 0< temp
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ echo sble01
sble01
+ echo ALLTEL WorkMon24Hrs
ALLTEL WorkMon24Hrs
+ echo Running
Running
+ [ ALLTEL WorkMon24Hrs != ALLTEL - WebOrders WorkActn ]
+ [ Running != Running ]
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ echo

+ echo
+ echo

+ [ ALLTEL WorkMon24Hrs != ALLTEL - WebOrders WorkActn ]
+ [  != Running ]
+ echo success
success
+ read SV_NAME CC_NAME CP_DISP_RUN_STATE
+ (( i=i+1 ))
+ [ 2 -eq 2 ]
Can you help me with this..
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:36 PM.


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

Content Relevant URLs by vBSEO 3.2.0