How to Use the getopt () function to parse parameters?
In the process of writing a program recently, part of the time is spent on Processing Parameters by the program. I heard from students about the getopt function today and found that c has a
A very important step in the programming of using getopt to parse command line parameters (c) CLI (command line interface) is the parsing of command line parameters. For the first brothers involved in this section, argv and argc are still very
The getopt function can be used to conveniently process command line parameters. The function is prototype:
Int getopt (INT argc, char * const argv [], const char * optstring );
The following are key points:1. argc, argv is the two of the main
Standard library function: getopt
Header file # include
Int getopt (INT argc, char * const argv [], const char * optstring );
Explanation: Take the argc and argv as passed to main function (the argc and argv parameters are the same as int main (INT
Recently done cache lab used the getopt function, with man 3 getopt view the following usage, make a summary.
Description: The Getopt function is used to parse command-line arguments, with an option element of '-' or '-' that starts with a '-' or '-
The shell getopts and getopt usage 1.getoptsgetopts (shell built-in command) cannot directly handle long options (such as:--prefix=/home, etc.), Getopts has two parameters, the first parameter is a string, including characters and ":", each
When I want to query the getopt function definition today, MAN 3 getopt gets the definition in Perl, And I want to define the getopt function in Linux, therefore, the man document is not completely installed. It doesn't matter. Just install man.
#
This article describes the use of command-line options and command-line arguments in a Linux shell, and in bash, you can use the following three ways to handle commands
Row parameters, each of which has its own application scenario
Question
Question Description: How do you deal with command-line options such as Tail-n Access.log in a Linux shell?
In bash, command line arguments can be handled in three ways, each with its own scenario.
1, direct processing, in turn to the $1,$2,..., $n,
In Bash, you can use the following three methods to process command lines:ParametersEach method has its own application scenario.1. perform direct processing, parse $1, $2,..., $ N in sequence, and perform manual processing respectively;2. getopts
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.