Hi,
I have a comma seperated list of values:
export list="red,blue,white,yellow"
Given a value in a variable "look", i want to check whether the value is available in the above list. But the result should be based on exact string match and not part of the string.
I am using following command:
echo $list | grep $look
For Eg:
-
When look="red", the above command returns "red,blue,white,yellow". This is CORRECT as i consider the value is present.
-
When look="green", the above command returns "" (BLANK). This is CORRECT as i consider the value is not present.
-
When look="low", the above command returns "red,blue,white,yellow". This is WRONG as low is not word but part of the 'yellow' word. The result should ideally give me ""(BLANK).
Can anybody help me out to overcome my problem OR is there any better way to check whether a given exact word is present in a list.
TIA
Warm Regards,
Ramesh