-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash.js
More file actions
30 lines (28 loc) · 680 Bytes
/
Copy pathbash.js
File metadata and controls
30 lines (28 loc) · 680 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
process.stdout.write('prompt > ');
const pwd = require('./pwd')
const ls = require('./ls')
const fs = require('fs')
process.stdin.on('data', (data) => {
const cmd = data.toString().trim();
const cmdArray = cmd.split(' ');
if(cmd === 'pwd'){
pwd();
}
else if(cmd === 'ls'){
ls();
}
else if (cmdArray[0] === 'cat') {
fs.readFile(`./${cmdArray[1]}`, 'utf8', function (err, data) {
if (err) {
throw err
}
process.stdout.write(data);
process.stdout.write('\nprompt > ');
})
}
else{
process.stdout.write('You typed: ' + cmd);
process.stdout.write("prompt > ");
}
// process.stdout.write('\nprompt > ');
})