Main article: C_syntax § Command-line_arguments
C uses argv to process command-line arguments.12
An example of C argument parsing would be:
C also has functions called getopt and getopt_long.
An example of C# argument parsing would be:
An example of Java argument parsing would be:
Here are some possible ways to print arguments in Kotlin:3
Perl uses @ARGV.
or
AWK uses ARGV also.
PHP uses argc as a count of arguments and argv as an array containing the values of the arguments.45 To create an array from command-line arguments in the -foo:bar format, the following might be used:
PHP can also use getopt().6
Python uses sys.argv, e.g.:
Python also has a module called argparse in the standard library for parsing command-line arguments.7
Racket uses a current-command-line-arguments parameter, and provides a racket/cmdline8 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:
Rexx uses arg, e.g.:
The args are in env::args().9
JavaScript programs written for Node.js use the process.argv global variable.10
Node.js programs are invoked by running the interpreter node interpreter with a given file, so the first two arguments will be node and the name of the JavaScript source file. It is often useful to extract the rest of the arguments by slicing a sub-array from process.argv.11
JavaScript written for Bun use Bun.argv and the util.parseArgs function.12
JavaScript written for Deno use Deno.args13 and the parseArgs function.14
"The C Book — Arguments to main". Publications.gbdirect.co.uk. Retrieved 2010-05-31. http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html ↩
An example of parsing C arguments and options http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style ↩
"Kotlin: Basic syntax". Retrieved 2022-05-13. https://kotlinlang.org/docs/basic-syntax.html#program-entry-point ↩
"PHP Manual". PHP. Retrieved 2010-05-31. http://php.net/manual/en/reserved.variables.argv.php ↩
wikibooks:PHP Programming/CLI https://en.wikibooks.org/wiki/PHP_Programming/CLI ↩
"PHP: Getopt - Manual". https://php.net/getopt ↩
"argparse — Parser for command-line options, arguments and sub-commands". Python v3.10.0 documentation. Archived from the original on 2012-11-01. Retrieved 15 October 2021. https://docs.python.org/3/library/argparse.html ↩
The Racket reference manual, Command-Line Parsing http://docs.racket-lang.org/reference/Command-Line_Parsing.html ↩
"Accepting Command Line Arguments - The Rust Programming Language". doc.rust-lang.org. Retrieved 22 December 2022. https://doc.rust-lang.org/book/ch12-01-accepting-command-line-arguments.html ↩
"process.argv". Node.js v10.16.3 Documentation. Retrieved 3 October 2019. https://nodejs.org/docs/latest-v10.x/api/process.html#process_process_argv ↩
"How to parse command line arguments". Node.js Foundation Documentation. Retrieved 3 October 2019. https://nodejs.org/en/knowledge/command-line/how-to-parse-command-line-arguments/ ↩
"Parse command-line arguments | Bun Examples". Bun. https://bun.sh/guides/process/argv ↩
"Deno.args". docs.deno.com. https://docs.deno.com/api/deno/~/Deno.args ↩
"parseArgs from parse-args - @std/cli - JSR". jsr.io. https://jsr.io/@std/cli/doc/parse-args/~/parseArgs ↩