String compare in shell script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

String compare in shell script

Shell Programming and Scripting


Tags
shell script, shell scripting, unix scripting, unix scripting basics

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-29-2008
kiranlalka kiranlalka is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 4 January 2011, 12:14 AM EST
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Question String compare in shell script

Iam trying to compare the string in if else... but some how its not working

following is the code

Quote:
if [ "${dbfiles[$l]}" -eq "${patchfiles[$k]}" ];
then
echo matched;
fi
On executing the above one its giving a error message ': bad number'

in the above parameter l & k are numbers and dbfiles and patchefiles are array

If i do echo ift working fine

echo ${dbfiles[$l]}

Iam trying to compare strings in array... any help on how it can be done.
Sponsored Links
    #2  
Old 11-29-2008
Christoph Spohr Christoph Spohr is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 29 September 2011, 1:45 PM EDT
Posts: 246
Thanks: 0
Thanked 8 Times in 8 Posts
Hi,

-eq is meant to compare numbers. Try "=" or "=~" depending on what you
want to achieve. For further information:


Code:
man test

HTH Chris
Sponsored Links
    #3  
Old 11-29-2008
kiranlalka kiranlalka is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 4 January 2011, 12:14 AM EST
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Christoph Spohr View Post
Hi,

-eq is meant to compare numbers. Try "=" or "=~" depending on what you
want to achieve. For further information:


Code:
man test

HTH Chris

Thx it worked.
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
Want a tcl script to compare a string in a file ignoring white spaces kulua Post Here to Contact Site Administrators and Moderators 1 04-30-2012 10:07 AM
Comparing a String variable with a string literal in a Debian shell script daveu7 UNIX for Dummies Questions & Answers 1 03-14-2012 08:37 AM
Shell Script to Compare Two Files scriptman237 Shell Programming and Scripting 3 07-09-2010 06:49 AM
Help me to identify whats wrong with below script | Just a string to string compare. KuldeepSinghTCS Shell Programming and Scripting 4 05-24-2010 03:12 AM
String compare with list in shell script rajinavaneethan Shell Programming and Scripting 2 06-11-2009 10:10 PM



All times are GMT -4. The time now is 07:41 PM.