Command Line Arguments ECE2893 Lecture 20 ECE2893 Command Line Arguments Spring 2011 1 / 5
Command Line Arguments ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ./drawing ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ./drawing We have also used many other command line programs: 3 ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ./drawing We have also used many other command line programs: 3 cp Copy ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ./drawing We have also used many other command line programs: 3 cp Copy cd Change Directory ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ./drawing We have also used many other command line programs: 3 cp Copy cd Change Directory make Build a program binary ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments All of our assignments do date have been command line 1 programs. We run them from a terminal window, and enter the name of the 2 program. ./drawing We have also used many other command line programs: 3 cp Copy cd Change Directory make Build a program binary Copy files from one computer to another rsync ECE2893 Command Line Arguments Spring 2011 2 / 5
Command Line Arguments ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). If an argument contains spaces, you can enclose it in double 3 quotes: ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). If an argument contains spaces, you can enclose it in double 3 quotes: mkdir "My New Directory" ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). If an argument contains spaces, you can enclose it in double 3 quotes: mkdir "My New Directory" You can also precede to space character with the escape 4 character (\) ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). If an argument contains spaces, you can enclose it in double 3 quotes: mkdir "My New Directory" You can also precede to space character with the escape 4 character (\) mkdir My\ New\ Directory ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). If an argument contains spaces, you can enclose it in double 3 quotes: mkdir "My New Directory" You can also precede to space character with the escape 4 character (\) mkdir My\ New\ Directory You can also use wildcards , such as the *: 5 ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments Almost all such programs read and process command line 1 arguments . cp drawing-skeleton.cc drawing.cc cd A8-LineDrawing The command line arguments follow the name of the program, 2 and are separated by spaces (whitespace). If an argument contains spaces, you can enclose it in double 3 quotes: mkdir "My New Directory" You can also precede to space character with the escape 4 character (\) mkdir My\ New\ Directory You can also use wildcards , such as the *: 5 ls -la *.cc ECE2893 Command Line Arguments Spring 2011 3 / 5
Command Line Arguments ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv argc is the count of arguments . 2 ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv argc is the count of arguments . 2 IMPORTANT: The program name itself is counted, so the value of argc is always at least one. ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv argc is the count of arguments . 2 IMPORTANT: The program name itself is counted, so the value of argc is always at least one. argv is a pointer to an array of char* values. 3 ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv argc is the count of arguments . 2 IMPORTANT: The program name itself is counted, so the value of argc is always at least one. argv is a pointer to an array of char* values. 3 Each of the array value points to a zero-byte-terminated character 4 string containing the value of the argument. ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv argc is the count of arguments . 2 IMPORTANT: The program name itself is counted, so the value of argc is always at least one. argv is a pointer to an array of char* values. 3 Each of the array value points to a zero-byte-terminated character 4 string containing the value of the argument. The value of argv[0] is always the name of the program. 5 ECE2893 Command Line Arguments Spring 2011 4 / 5
Command Line Arguments The complete list of arguments is passed to the C main function 1 as two arguments: int argc char** argv argc is the count of arguments . 2 IMPORTANT: The program name itself is counted, so the value of argc is always at least one. argv is a pointer to an array of char* values. 3 Each of the array value points to a zero-byte-terminated character 4 string containing the value of the argument. The value of argv[0] is always the name of the program. 5 The value of argv[argc] is always NULL 6 ECE2893 Command Line Arguments Spring 2011 4 / 5
Recommend
More recommend