Command-line argument parsing
Encyclopedia
Different Command-line argument parsing methods are used by different programming languages to parse command-line arguments.
argument parsing would be:
uses
PHP can also use
uses
The library parses long and short flags, handles arguments, allows combining short flags, and handles
C
C usesargv
to process command-line arguments.Java
An example of JavaJava (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
argument parsing would be:
PHP
PHPPHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
uses
argc
as a count of arguments and argv
as an array containing the values of the arguments. To create an array from command-line arguments in the -foo:bar
format, the following might be used:PHP can also use
getopt
Python
PythonPython (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
uses
sys.argv
, e.g.:Racket
Racket uses acurrent-command-line-arguments
parameter, and provides a racket/cmdline
library for parsing these arguments. Example:The library parses long and short flags, handles arguments, allows combining short flags, and handles
-h
and --help
automatically:
$ racket /tmp/c -nfe 8
8-(