[PATCH v2 14/27] env: Split out non-command code into a new file