diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index 31ce752f9b9..382ce15a118 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -84,6 +84,16 @@ Vector Parser::parse() m_state = State::InRedirectionPath; break; } + if (ch == '\\') { + if (i == m_input.length() - 1) { + fprintf(stderr, "Syntax error: Nothing to escape (\\)\n"); + return {}; + } + char next_ch = m_input.characters()[i + 1]; + m_token.append(next_ch); + ++i; + break; + } if (ch == '\'') { m_state = State::InSingleQuotes; break; @@ -147,6 +157,21 @@ Vector Parser::parse() m_state = State::Free; break; } + if (ch == '\\') { + if (i == m_input.length() - 1) { + fprintf(stderr, "Syntax error: Nothing to escape (\\)\n"); + return {}; + } + char next_ch = m_input.characters()[i + 1]; + if (next_ch == '$' || next_ch == '`' + || next_ch == '"' || next_ch == '\\') { + m_token.append(next_ch); + ++i; + continue; + } + m_token.append('\\'); + break; + } m_token.append(ch); break; };