mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
Shell: Add the POSIX-only 'eval' builtin
This just concatenates its arguments together, and executes it as a command.
This commit is contained in:
parent
e2af20a69b
commit
21ea9cedff
2 changed files with 26 additions and 0 deletions
|
@ -540,6 +540,31 @@ ErrorOr<int> Shell::builtin_dirs(Main::Arguments arguments)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ErrorOr<int> Shell::builtin_eval(Main::Arguments arguments)
|
||||
{
|
||||
if (!m_in_posix_mode) {
|
||||
warnln("eval: This shell is not in POSIX mode");
|
||||
return 1;
|
||||
}
|
||||
|
||||
StringBuilder joined_arguments;
|
||||
for (size_t i = 1; i < arguments.strings.size(); ++i) {
|
||||
if (i != 1)
|
||||
joined_arguments.append(' ');
|
||||
joined_arguments.append(arguments.strings[i]);
|
||||
}
|
||||
|
||||
auto result = Posix::Parser { TRY(joined_arguments.to_string()) }.parse();
|
||||
if (!result)
|
||||
return 1;
|
||||
|
||||
auto value = TRY(result->run(*this));
|
||||
if (value && value->is_job())
|
||||
block_on_job(static_cast<AST::JobValue*>(value.ptr())->job());
|
||||
|
||||
return last_return_code.value_or(0);
|
||||
}
|
||||
|
||||
ErrorOr<int> Shell::builtin_exec(Main::Arguments arguments)
|
||||
{
|
||||
if (arguments.strings.size() < 2) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue