Question: Design and implement C/C++ program (a2part4.c and its executable named a2part4) to process command (to tokenize and parse the command, and print its components correctly).

Design and implement C/C++ program (a2part4.c and its executable named a2part4) to process command (to tokenize and parse the command, and print its components correctly).

Your C/C++ program starts and runs in a loop (to input a line of command at a time, to parse it, and to output the parsed tokens, and back to a loop). Also provide Makefile to compile the program to generate its executable.

For each input, your program should be able to parse each command from user (to process one command after the other in a loop) and print the result of the parsing, until the user's input is "exit" to terminate the program.

Examples (You may create your own output format or template to show the command(s) being parsed.)

Run your program for each of the following examples (test case), to show that it is working correctly.

Test#1. One command with argument

For example (for the input),

touch sample.txt

Your program should output:

Command: touch

Argument: sample.txt

Test#2. One command with arguments and options.

For example (for the input),

ls i sample.txt

Your program should output:

Command: ls

Option: i

Argument: sample.txt

Test#3. One command with arguments and options.

For example (for the input),

ls la $HOME

Your program should output:

Command: ls

Option: l

Option: a

Arguments: $HOME

Test#4. One command with arguments and options.

For example (for the input),

ls l a $HOME

Your program should output:

Command: ls

Option: l

Option: a

Arguments: $HOME

Test#5. One command with IO redirection symbol (<, >, >>)

For example, sort < sample.txt

Command: sort

File Redirection: <

File: sample.txt

Test#6. One command with IO redirection symbol (<, >, >>)

For example, sort < input.txt > output.txt

Command: ls

File Redirection: <

File: input.txt

File Redirection: >

File: output.txt

Test#7. Two commands with pipe.

For example, ls | sort should be parsed and display

Command: ls

Pipe

Command: sort

Test#8. Three commands with pipe.

For example, ls | sort | wc should be parsed and display

Command: ls

Pipe

Command: sort

Pipe

Command: wc

Part4 Solution

Task #1-#8. myShell1.c

Listing of your program source code (a2part4.c) here

Listing of Makefile to compile and generate binary executable (a2part4)

Copy and paste the program run (a2part4run.txt) here

Task#1

Task#2

Task#3

Task#4

Task#5

Task#6

Task#7

Task#8

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!