diff --git a/src/Environment.cc b/src/Environment.cc index 7c2f02f..b18824f 100644 --- a/src/Environment.cc +++ b/src/Environment.cc @@ -17,8 +17,10 @@ #include +#include #include #include +#include extern char ** environ; @@ -165,7 +167,13 @@ bool setenv(const EnvironmentMap &_vars) std::string printenv() { std::string ret; - for (const auto &[key, value] : env()) + // Variables are in an unordered_map as we generally don't + // care, but for printing sort for consistent display + auto currentEnv = env(); + auto sorted = std::vector>( + currentEnv.begin(), currentEnv.end()); + std::sort(sorted.begin(), sorted.end()); + for (const auto &[key, value] : sorted) { ret.append(key); ret.append("=");