Linux operating system program command line Processing Analysis

Source: Internet
Author: User
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:
QUOTE:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.