Tweak this script for dash compatibility.

dash requires `local` appear as the first statement of a function.