Shell: Add append operator (>>)

Fixes #93.
This commit is contained in:
Robin Burchell 2019-05-26 00:38:11 +02:00 committed by Andreas Kling
parent c6e79bd53a
commit aee99b05a6
Notes: sideshowbarker 2024-07-19 13:56:58 +09:00
3 changed files with 72 additions and 37 deletions

View file

@ -60,7 +60,9 @@ Vector<Subcommand> Parser::parse()
if (ch == '>') {
commit_token();
begin_redirect_write(STDOUT_FILENO);
m_state = State::InRedirectionPath;
// Search for another > for append.
m_state = State::InWriteAppendOrRedirectionPath;
break;
}
if (ch == '<') {
@ -79,6 +81,18 @@ Vector<Subcommand> Parser::parse()
}
m_token.append(ch);
break;
case State::InWriteAppendOrRedirectionPath:
if (ch == '>') {
commit_token();
m_state = State::InRedirectionPath;
ASSERT(m_redirections.size());
m_redirections[m_redirections.size() - 1].type = Redirection::FileWriteAppend;
break;
}
// Not another > means that it's probably a path.
m_state = InRedirectionPath;
[[fallthrough]];
case State::InRedirectionPath:
if (ch == '<') {
commit_token();