summaryrefslogtreecommitdiff
path: root/Shell
diff options
context:
space:
mode:
authorKarol Baraniecki <karol@baraniecki.eu>2019-12-03 17:38:32 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-12-05 17:08:37 +0100
commit7ed8a468ec9da8f03dc791926591ebaafd54b185 (patch)
treec072a7680558e0e757cfbfa306fc50bb35185715 /Shell
parentcf7910fc1e8969e01cf006ee0000f2cc030c6811 (diff)
downloadserenity-7ed8a468ec9da8f03dc791926591ebaafd54b185.zip
Shell: Implement specifying fds in file redirection
Diffstat (limited to 'Shell')
-rw-r--r--Shell/Parser.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp
index 382ce15a11..2280ef4057 100644
--- a/Shell/Parser.cpp
+++ b/Shell/Parser.cpp
@@ -1,6 +1,7 @@
#include "Parser.h"
#include <stdio.h>
#include <unistd.h>
+#include <ctype.h>
void Parser::commit_token()
{
@@ -102,6 +103,28 @@ Vector<Command> Parser::parse()
m_state = State::InDoubleQuotes;
break;
}
+ if (isdigit(ch)) {
+ if (i != m_input.length() - 1) {
+ char next_ch = m_input.characters()[i + 1];
+ if (next_ch == '>') {
+ commit_token();
+ begin_redirect_write(ch - '0');
+ ++i;
+
+ // Search for another > for append.
+ m_state = State::InWriteAppendOrRedirectionPath;
+ break;
+ }
+ if (next_ch == '<') {
+ commit_token();
+ begin_redirect_read(ch - '0');
+ ++i;
+
+ m_state = State::InRedirectionPath;
+ break;
+ }
+ }
+ }
m_token.append(ch);
break;
case State::InWriteAppendOrRedirectionPath: