-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-shell.cpp
More file actions
29 lines (26 loc) · 1003 Bytes
/
simple-shell.cpp
File metadata and controls
29 lines (26 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <cstdlib>
void simpleShell() {
std::string command;
while (true) {
std::cout << "TB_Shell >>";
std::getline(std::cin, command);
if (command == "exit" || command == "quit") {
std::cout << "Exiting shell..." << std::endl;
break;
} else if (command.empty()) {
continue;
} else if (command.find("touch") == 0 || command.find("cat") == 0 || command.find("echo") == 0 ||
command.find("rm") == 0 || command.find("mv") == 0 || command.find("cp") == 0 ||
command.find("ls") == 0 || command.find("chmod") == 0 || command.find("chown") == 0) {
system(command.c_str());
} else {
std::cout << "Unsupported command. Use basic file operations like touch, cat, echo, rm, mv, cp, ls, chmod, chown." << std::endl;
}
}
}
int main() {
simpleShell();
return 0;
}