-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.js
More file actions
32 lines (22 loc) · 750 Bytes
/
bash.js
File metadata and controls
32 lines (22 loc) · 750 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
30
31
32
const commands = require('./command.js');
const fs = require("fs");
process.stdout.write('prompt > ');
process.stdin.on('data', function (data) {
var cmd = data.toString().trim();
if (cmd === "PWD") {
commands.pwd();
} else if (cmd === "Date") {
commands.date();
} else if (cmd === "LS") {
fs.readdir('.', function(err, files) {
if (err) throw err;
files.forEach(function(file) {
process.stdout.write(file.toString() + "\n");
})
process.stdout.write("prompt > ");
});
} else if (cmd === "echo") {
process.stdout.write(process.argv2 + "\n");
process.stdout.write("prompt >");
}
});