string comparision in linux scripts
Hi,
I wanted help in string comparison in linux scripts. I have two strings of different lenght namely s1="abcdefgh" s2="abcdef" Now I want to compare string s2 with s1. I know how to compare strings of same length but how to compare strings of different length I am unaware. Please help. Ravi Modi. |
This web site explains the bash programming basics. Use = for strings and -eq for numeric comparisons.
http://www.geocities.com/tipsforlinu...cles2/043.html |
What exactly do you want the test to check? If you know they're different lengths, do you want to test if the shorter string is the first part of the longer or what? You already know they aren't equal strings...???
|
I actually want to check whether the first 6 characters of larger
string is equal to shorter string (the shorter string is of 6 characters). I have above just given example & actually I am not aware of the string contents before hand. |
So you either want the 6 characters long substring from the beginning of the longer string (will it be know which is the longer?) and compare this new string to the second string, or just walk the first 6 chars of each string and compare each in turn..?
|
I am having two strings. one is shorter (s2) of 6 characters and another
is longer (s1) of 8 characters. I am knowing before hand which string is shorter & which is longer. Also the length of shorter and longer string is known. Now I want to compare whether the first 6 characters of longer string (s1) is equal to shorter string(s2). |
A quick googling of bash string comparisons reveales this:
Quote:
|
Code:
ff() abcdefgh abcdef -> match zzzzzzzz abcdef -> do not match |
All times are GMT -5. The time now is 07:19 PM. |