env-setup tweaks (POSIX-compliance)

This series of commits turns env-setup into a POSIX-compliant shell script, so that it can be used from shells like dash and ksh just the same.