#include #include "shellenv.h" // // Example: // shellenv("aap noot mies", "LEESPLANK", SHELL_SH); // returns the string: // LEESPLANK='aap noot mies';export LEESPLANK; // // "'" characters in s are escaped // std::string shellenv(std::string s, const std::string name, int shelltype) { std::string r = "'"; std::string::iterator it; for ( it=s.begin() ; it < s.end(); it++ ) { if ( *it == '\'') { r.push_back('\''); r.push_back('\\'); r.push_back('\''); r.push_back('\''); } else r.push_back(*it); } r.push_back('\''); switch (shelltype) { case SHELL_CSH: r = "setenv " + name + " " + r + ";\n"; break; case SHELL_SH: r = name + "=" + r + ";" + "export " + name + ";\n"; break; } return r; }