2778 fix shell corrupt

Fixes #2778. /cc @vieux @crosbymichael