Make read-shell-env more robust