File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 1
1
const readline = require ( "readline" ) ;
2
2
3
- const commands = [ "exit" , "echo" ] ;
3
+ const commands = [ "exit" , "echo" , "type" ] ;
4
4
5
5
let terminal = true ;
6
6
@@ -13,14 +13,20 @@ const promptUser = () => {
13
13
rl . question ( "$ " , ( answer ) => {
14
14
const promptArray = answer . split ( " " ) ;
15
15
const userCommand = promptArray [ 0 ] ;
16
- const userInput = promptArray . slice ( 1 ) ;
16
+ const userInput = promptArray . slice ( 1 ) . join ( " " ) ;
17
17
if ( ! commands . includes ( userCommand ) ) {
18
18
console . log ( `${ userCommand } : command not found` ) ;
19
19
} else if ( userCommand === "exit" ) {
20
20
rl . close ( ) ;
21
21
process . exit ( 0 ) ;
22
22
} else if ( userCommand === "echo" ) {
23
- console . log ( userInput . join ( " " ) ) ;
23
+ console . log ( userInput ) ;
24
+ } else if ( userCommand === "type" ) {
25
+ if ( commands . includes ( userInput ) ) {
26
+ console . log ( `${ userInput } is a shell builtin` ) ;
27
+ } else {
28
+ console . log ( `${ userInput } : not found` ) ;
29
+ }
24
30
}
25
31
if ( terminal ) {
26
32
promptUser ( ) ;
You canβt perform that action at this time.
0 commit comments