Skip to content

Commit 5dd62f3

Browse files
committed
echo command
1 parent b124956 commit 5dd62f3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include <iostream>
22
#include <string>
33

4+
void do_exit(std::string args) {
5+
int exit_code = std::stoi(args);
6+
exit(exit_code);
7+
}
8+
9+
void do_echo(std::string args) {
10+
std::cout << args << std::endl;
11+
}
12+
413
int main() {
514
// Flush after every std::cout / std:cerr
615
std::cout << std::unitbuf;
@@ -13,9 +22,12 @@ int main() {
1322
std::string cmd = input.substr(0, input.find(' '));
1423
std::string args = input.substr(input.find(' ') + 1);
1524
if (cmd == "exit") {
16-
exit(std::stoi(args));
25+
do_exit(args);
26+
}
27+
else if (cmd == "echo") {
28+
do_echo(args);
1729
}
18-
if (input != "") {
30+
else if (input != "") {
1931
std::cout << input << ": command not found" << std::endl;
2032
}
2133
} while(input != "");

0 commit comments

Comments
 (0)