Question
Create a subdirectory of your home directory named msh. (for my shell) Copy /home/CLASSES/brunsglenn/spring17/hw/hw2/hello.c to your msh directory. Compile and run hello.c. to compile: $
Create a subdirectory of your home directory named msh. (for my shell)
Copy /home/CLASSES/brunsglenn/spring17/hw/hw2/hello.c to your msh directory.
Compile and run hello.c.
to compile: $ gcc -o hello hello.c
to run: $ ./hello
Copy hello.c to msh.c
Modify msh.c so that, instead of hello, world!, it prints msh> . Compile and run. (Note the space after >.)
Add code right after the printf statement so that you read in keyboard input from the user. Also. modify your program so that, after it gets the user input, the input is printed. Hint: consider using fgets to get user input. Test your program by trying different kinds of user input.
Add code right after displaying the user input to check whether the user input the string exit. If so, print exiting. Compile and test again.
Put your code within a loop so that you:
prompt for input with msh>
read the input that the user types
if the user types exit, exit the program, but otherwise report what the user typed (as in part f), and then prompt for new input.
After getting the user input, break it 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: you can use C library functions strtok.
Use fork and exec as in OSTEP Figure 5.3 to execute whatever Linux command the user enters. After executing the command, the prompt should be displayed as usual.
Make it so that your shell exits when either exit is entered, or end of file ^d is entered.
Add a help command that your msh will execute itself. Decide for yourself what your help command will print.
Add a today command that will print the current date in the format
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started