awk is a completely seperate command and language to shells. the variables do NOT match up.
You can feed in shell variables into awk by using double quotes, but that only sets the variable contents as a constant value, not as a varable into awk.
For output you need to some how get that result back into a shell variable. typically you get awk to print it and then read the output into a shell variable.
Code:
d="string"
i=`awk '{if( $1 == "'"$d"'" ) i=2 } END {print i}' file`
echo "$i"
If you are outputting a file and want the variable, then you need to start getting even trickier, and use awk and shell file destriptors and or temporary files.
For multiple variables you can have awk generate 'shell commands' and "eval" the output results. THIS IS DANGERIOUS security wise.
Code:
d="string"
eval `awk '{if( $1 == "'"$d"'" ) a=2; b=3 } END {print "a=" a "; b=" b }' file`
echo "a=$a b=$b"
Another less dangeriosu method is to use "set" on the awk output to place the output 'words' into the shell variable $1 $2 etc..
Code:
d="string"
set -- `awk '{if( $1 == "'"$d"'" ) a=2; b=3 } END {print a, b }' file`
echo "a=$1 b=$2"
All these tricky methods are listed (somewhere) in teh Advanced BASH Shell Scripting Guide
http://www.tldp.org/LDP/abs/html/index.html
PS: I have been shell programming for more than 30 years now, and have developed and used such methods continuiously over than time. No just for awk, but sed, perl, and many other programs. The methods are pretty much the same no matter what command you use.
NOTE this topic is not really appropriate for non-*nix forum. But then as there is not specific 'shell programming' forum, where it should go is a problem. Best place seems to be "linux-general".