Protect reference to $? in embedded script.

Reviewed at https://reviews.apache.org/r/16462/