Linux operating system program command line Processing Analysis-Linux general technology-Linux programming and kernel information, the following is a detailed reading. GNU/Linux Command Line habits
Almost all GNU/Linux programs follow the same command line interpretation habits. program parameters are generally divided into two categories: option, flag, and other parameters. Option is mainly used to provide some running options for the program, while other parameters are usually provided to the program running input and other values. According to habits, there are two forms of expressions for options:
Short form: it is usually composed of A hyphen (-) and a letter. The advantage of this form is quick input.
Long form: it is usually composed of two "-" And one word. The benefits of this form are image, note, and intuition.
Generally, a program can be read in both forms. For example, most programs have the following call options: "-h" and "? Help ". Some options need to know the following parameters, such as "ls? S/", where"/"is a parameter.
Use the getopt_long function for processing
The analysis and processing of a command line is tedious and requires a lot of operations such as string matching. Fortunately, the gnu c function library provides a function that makes this job much easier. Of course, it may not be as easy as you think. The getopt_long function can "understand" parameters in both the long form and short form.
Next we will use an instance to learn how to use this function.
Assume that the program we want to write needs to process the following parameters: