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