Currently when I run adb devices it gives me a list of devices that looks something like:
emulator-5554    device
emulator-5556    device
My goal is to find a command that I can run in the shell that takes a device name as a parameter, e.g. Nexus7 and returns the corresponding device serial, e.g. emulator-5554.  If that isn't possible, I want to be able to have a function that takes emulator-5554 as the parameter and returns Nexus7 (the opposite direction of the former function) which I will then loop over all the devices in adb devices and figure out which one matches Nexus7.
UPDATE
I found a workaround solution which was to specify the port number when I launch the avd and then I know which emulator maps to which avd name, but ideally I would still like to know the answer here.