it is just like rtmistler said.
on my system:
Code:
export MYTHEME="$( grep gtk-theme $GTK2_RC_FILES | cut -d '"' -f 2)"
the theme folder's name and the theme's name don't always match, but this gives you the actual theme's name.
if you actually need the folder, um, more tricky.
i suggest you check out gtk2 documentation. it's very dry and dev-oriented.
edit:
try "env" or "printenv", maybe you don't have to reinvent the wheel.