Question: Extend your msh.c code from below: ***************** msh.c ********************* #include #include int main(){ char str[1000]; printf(msh> ); fgets(str, 120, stdin); while(strcmp(str, exit )!=0) { if(feof(stdin)){

Extend your msh.c code from below:

***************** msh.c *********************

#include

#include

int main(){

char str[1000];

printf("msh> ");

fgets(str, 120, stdin);

while(strcmp(str, "exit ")!=0) {

if(feof(stdin)){

break;

}

int len = strlen(str);

if(len>120){

printf("msh> error: input too long ");

}else if(len>1){

printf("%s", str);

}

printf("msh> ");

fgets(str, 1000, stdin);

}

return 0;

}

**********************************************

1) as before, exit msh when exit or ctrl-d is entered

2) run Linux commands that are entered by the user. You must do this by using fork and exec

I recommend that you implement this feature by first breaking the user input into tokens. The tokens are the strings in the input line separated by whitespace (spaces or tabs). The tokens should not include any whitespace. For example, on input

msh> wc -l

there are two tokens: wc and -l. Hint: use C library function strtok to break the user input into tokens.

3) Add a help command that will simply display enter Linux commands, or exit to exit

4) Add a today command that will print the current date in the format mm/dd/yyyy, where mm is month, dd is day of month, and yyyy is year. For example, 01/02/2018 is January 2, 2018

DO NOT USE 'system' command to execute shell commands

************* Sample output of the program *************

$ msh

msh> ls

temp.txt README.txt

msh> help

enter Linux commands, or exit to exit

msh> foo 1

msh: foo: No such file or directory

msh> today

01/02/2018

msh> exit

$

***********************************************************

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!