summaryrefslogtreecommitdiff
path: root/Shell/AST.cpp
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-08-04 09:27:25 +0430
committerAndreas Kling <kling@serenityos.org>2020-08-04 13:40:58 +0200
commit12af65c1c9e29e1958bcd1df1e1566adc74aa8f6 (patch)
treefd9141ed2b0012437b7b23b2c5f381288741d5f7 /Shell/AST.cpp
parent192b2383ac8ac06a9428d6e12c2003ef98625f24 (diff)
downloadserenity-12af65c1c9e29e1958bcd1df1e1566adc74aa8f6.zip
Shell: Add support for ARGV (and $*, $#)
This patchset also adds the 'shift' builtin, as well as the usual tests. closes #2948.
Diffstat (limited to 'Shell/AST.cpp')
-rw-r--r--Shell/AST.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/Shell/AST.cpp b/Shell/AST.cpp
index 262c168a80..8639bdc90b 100644
--- a/Shell/AST.cpp
+++ b/Shell/AST.cpp
@@ -2004,6 +2004,7 @@ RefPtr<Value> SimpleVariableValue::resolve_without_cast(RefPtr<Shell> shell)
SpecialVariableValue::~SpecialVariableValue()
{
}
+
Vector<String> SpecialVariableValue::resolve_as_list(RefPtr<Shell> shell)
{
switch (m_name) {
@@ -2011,6 +2012,19 @@ Vector<String> SpecialVariableValue::resolve_as_list(RefPtr<Shell> shell)
return { String::number(shell->last_return_code) };
case '$':
return { String::number(getpid()) };
+ case '*':
+ if (auto argv = shell->lookup_local_variable("ARGV"))
+ return argv->resolve_as_list(shell);
+ return {};
+ case '#':
+ if (auto argv = shell->lookup_local_variable("ARGV")) {
+ if (argv->is_list()) {
+ auto list_argv = static_cast<AST::ListValue*>(argv.ptr());
+ return { String::number(list_argv->values().size()) };
+ }
+ return { "1" };
+ }
+ return { "0" };
default:
return { "" };
}