make variable substitution work in command substitution

This fixes #129. Check the new regression test case for details.