Shell: Cleanup `export` builtin
This commit is contained in:
parent
28275d86ea
commit
7edfae8583
|
@ -39,20 +39,17 @@ void Builtin::initialize()
|
||||||
MUST(m_builtin_commands.emplace("export"_sv,
|
MUST(m_builtin_commands.emplace("export"_sv,
|
||||||
[](Execute&, BAN::Span<const BAN::String> arguments, FILE*, FILE*) -> int
|
[](Execute&, BAN::Span<const BAN::String> arguments, FILE*, FILE*) -> int
|
||||||
{
|
{
|
||||||
bool first = false;
|
for (size_t i = 1; i < arguments.size(); i++)
|
||||||
for (const auto& argument : arguments)
|
|
||||||
{
|
{
|
||||||
if (first)
|
const auto argument = arguments[i].sv();
|
||||||
{
|
|
||||||
first = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto split = MUST(argument.sv().split('=', true));
|
const auto idx = argument.find('=');
|
||||||
if (split.size() != 2)
|
if (!idx.has_value())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (setenv(BAN::String(split[0]).data(), BAN::String(split[1]).data(), true) == -1)
|
auto name = BAN::String(argument.substring(0, idx.value()));
|
||||||
|
const char* value = argument.data() + idx.value() + 1;
|
||||||
|
if (setenv(name.data(), value, true) == -1)
|
||||||
ERROR_RETURN("setenv", 1);
|
ERROR_RETURN("setenv", 1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue