Question: Argument Passing Through the Command Line Objective To pass information from the shell command line to a running program and to understand the operating system's



Argument Passing Through the Command Line Objective To pass information from the shell command line to a running program and to understand the operating system's roll during this interaction. Description Most of the utilities/commands in Linux are written in C. Many of these commands accept input(s) fromm the user, in the form of flags and arguments, and react differently to different inputs (e.g. gcc-o temp sample1.c) The OS reads the user input from the command line, creates standard structures and passes them to the main program of the command. If the programmer of this command can access these structures, by declaring arguments in the definition of the main program. A common convention uses arge and argv as follows void main (int argc, char **argv)..1 where int arg: argument count, which is the number of tokens typed on the command line - char **argv: argument vector, which is an array of these token:s Now, argc and argv are local variables the programmer can read and use to direct the execution of the command Submission Submit one compressed file that contains the following programs 1. Printing all arguments passed through the command "MyCommand1" Your first deliverable is a C program (MyCommand1.c) that: - prints all the arguments that are passed to it through the command line (see figure below) SMyCommand1 Argl Arg2 $MyCommandl Arg1 Arg2 Arg3 Arg4 argv [0]: MyCommand! argv 1]: Argil argv[2]: Arg2 argv[0]: MyCommand1 argv[1]: Arg1 argv[2]: Arg2 argv[3]: Arg3 argv 4] Arg4 Figure 1- Sample runs of MyCommand1 with different inputs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
