comparing content of 2 variables in script

hello
how can i compare the content of two variables using the if or for loops.
I have 2 variables which was formed as result of commands pass into them but i want to now compare the 2 contents and echo where their is a match
for examples
variable1=`cat file2`
variable2=`cat file3`
if [ `$variable1` = `$variable2` ] # looking for content match of strings
then
echo "variable1"
else
echo " no match found"
fi

if you're comparing files, 'man comm'

Thanks for the reply
its not realy a file but an output .
Am actually doing this
variable1=`cat /etc/passwd | cut -d ':' -f5` #getting the username
variable2=`who` # logging user
now am comparing this two variable if thier some match then it would echo those match ie where the username matches the logging then it produce the logging name

variable1=`cat file2`
variable2=`cat file3`
if [ "$variable1" = "$variable2" ] # looking for content match of strings
then
   echo "variable1"
else
   echo " no match found"
fi

Jean-Pierre.

@Sam

You are using who command. In a network if multiple users logs in then you will get lots of output.

x033870@agamemnon:/home/x033870>who
c028407 pts/1 Mar 27 10:31 (GDISpcp286146pcs.mis.amat.com)
c028407 pts/2 Mar 3 11:23 (GDISpcp286146pcs.mis.amat.com)
c028407 pts/3 Mar 20 22:10 (GDISpcp286146pcs.mis.amat.com)
c028407 pts/4 Mar 11 11:29 (GDISpcp286146pcs.mis.amat.com)
c028407 pts/6 Mar 28 14:22 (GDISpcp286146pcs.mis.amat.com)
x033870 pts/7 Apr 24 11:35 (KLXVF2D.mis.amat.com)
c028407 pts/8 Apr 2 10:17 (GDISpcp286146pcs.mis.amat.com)
c028407 pts/9 Apr 2 10:19 (GDISpcp286146pcs.mis.amat.com)

What you want to acheive here. Can you tell me the exact requirement.

you cannot do it like this - you need to iterate through the logged in users. Something along these lines:

#!/usr/bin/ksh

who | while read id junk
do
   awk -F: -v id="${id}" '$1 == id { print $5;exit}' /etc/passwd
done | sort -u