mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
sh: Add a simple "export" command for setting environment variables.
This commit is contained in:
parent
490e89e240
commit
d4a8e2930e
Notes:
sideshowbarker
2024-07-19 14:34:56 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d4a8e2930e1
1 changed files with 20 additions and 0 deletions
|
@ -65,6 +65,22 @@ static int sh_exit(int, char**)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sh_export(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc == 1) {
|
||||||
|
for (int i = 0; environ[i]; ++i)
|
||||||
|
puts(environ[i]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto parts = String(argv[1]).split('=');
|
||||||
|
if (parts.size() != 2) {
|
||||||
|
fprintf(stderr, "usage: export variable=value\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
putenv(const_cast<char*>(String::format("%s=%s", parts[0].characters(), parts[1].characters()).characters()));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int sh_cd(int argc, char** argv)
|
static int sh_cd(int argc, char** argv)
|
||||||
{
|
{
|
||||||
char pathbuf[PATH_MAX];
|
char pathbuf[PATH_MAX];
|
||||||
|
@ -120,6 +136,10 @@ static bool handle_builtin(int argc, char** argv, int& retval)
|
||||||
retval = sh_exit(argc, argv);
|
retval = sh_exit(argc, argv);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(argv[0], "export")) {
|
||||||
|
retval = sh_export(argc, argv);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue