Computing.Net > Forums > Unix > Fail to compare two strings

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Fail to compare two strings

Reply to Message Icon

Name: jenny.han
Date: March 19, 2003 at 23:18:56 Pacific
OS: UNIX
CPU/Ram: 2G
Comment:

I need to compare two report names, that is, two strings.

When I tried to use the following expression:
if (( $word1 -eq $rptname ))
or
if [[ $word1 -eq $rptname ]]

system report: syntax error

If I use the following expression:
if ( $word1 -eq $rptname )

System seems to think the two strings are different, but they are the same, I can see use ECHO command.

Can anyone kindly advise the correct expression? Or maybe there is some other thing wrong?

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: March 20, 2003 at 05:42:43 Pacific
Reply:

-eq is for matching integers, and (()) is for integer expressions.

Try

if [[ $word1 = $rptname ]]
then
print Match
else
print No match
fi

For integers you could use

integer int1=1 int2=2

if (( int1 == int2 ))
then
print Match
else
print No match
fi

Note that '=' becomes an assignment operator inside (()).


0

Response Number 2
Name: jenny.han
Date: March 23, 2003 at 19:50:26 Pacific
Reply:

Thanks William,

Using your ways, I have been successful getting the results.

Thanks so much!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Fail to compare two strings

comparing strings in unix www.computing.net/answers/unix/comparing-strings-in-unix/3309.html

compare two files field string www.computing.net/answers/unix/compare-two-files-field-string/8078.html

comparing two files www.computing.net/answers/unix/comparing-two-files/8256.html