×
UNIX.COM Login
Username:
Password:  
Show Password





×
UNIX.COM Login
Hello Unregistered
Welcome from United States
You are somewhere around Ashburn
Last Visit: 1 Minute Ago @ 03:22 PM
Bits: 0
UNIX Time: 1531682576

👤


UNIX for Advanced & Expert Users

Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Comparing strings

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-22-2007   -   Original Discussion by yakyaj
yakyaj's Unix or Linux Image
yakyaj yakyaj is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 4 June 2007, 1:20 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Comparing strings

I have two strings
a=Mar22
b=may21

how can I compare them
Is this fine

if[ $a -eq $b ] then;
.
...

else
....
fi

or
if[ $a = $b ] then
Sponsored Links
    #2  
Old 03-22-2007   -   Original Discussion by yakyaj
varungupta's Unix or Linux Image
varungupta varungupta is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 15 July 2010, 5:53 AM EDT
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Thanks: 0
Thanked 1 Time in 1 Post
for string comparisions we generally use = operator.
-eq is used for integer comparisons.
if [ "str1" = "str2" ] then

fi

will do your task .
Sponsored Links
    #3  
Old 03-23-2007   -   Original Discussion by yakyaj
yakyaj's Unix or Linux Image
yakyaj yakyaj is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 4 June 2007, 1:20 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Many Thanks.It worked now. I tried with out " ".
Sponsored Links
👤 Login to reply

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
Comparing strings with sed cola Shell Programming and Scripting 7 08-22-2010 11:51 AM
comparing two strings infyanurag Shell Programming and Scripting 1 10-15-2008 02:38 AM
comparing 2 strings satish@123 Shell Programming and Scripting 2 05-16-2008 07:59 AM
comparing strings agarwal Shell Programming and Scripting 3 04-16-2008 05:29 AM
Comparing Two Strings Anji Shell Programming and Scripting 8 01-09-2008 05:32 AM



All times are GMT -4. The time now is 03:22 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.