Command-line argument parsing

Different command-line argument parsing methods are used by different programming languages to parse command-line arguments.
Programming languages.
C.
C uses codice_1 to process command-line arguments.
An example of C argument parsing would be:
int main (int argc, char *argv[])
 int count;
 for (count=0; count<argc; count++)
 puts (argv[count]);
C also has functions called getopt and getopt_long.
Java.
An example of Java argument parsing would be:
public class Echo {
 public static void main (String[] args) {
 for (String s: args) {
 System.out.println(s);
Perl.
Perl uses codice_2.
foreach $arg (@ARGV)GT
 print $arg;
FT
or
foreach $argnum (0 .. $#ARGV)ST
 print $ARGV[$argnum];
AWK.
AWK uses codice_3 also.
BEGIN {
 for ( i = 0; i < ARGC; i++ )
 print ARGV[i]
PHP.
PHP uses codice_4 as a count of arguments and codice_1 as an array containing the values of the arguments. To create an array from command-line arguments in the codice_6 format, the following might be used:
$args = parseArgs($argv);
echo getArg($args, 'foo');
function parseArgs(array $args)
 foreach ($args as $arg) {
 $tmp = explode(':', $arg, 2);
 if ($arg[0] === '-') {
 $args[substr($tmp[0], 1)] = $tmp[1];
 return $args;
function getArg(array $args, string $arg)
 if (isset($args[$arg])) {
 return $args[$arg];
 return false;
PHP can also use codice_7.
Python.
Python uses codice_8, e.g.:
import sys
for arg in sys.argv:
 print arg
Python also has a module called codice_9 in the standard library for parsing command-line arguments.
Racket.
Racket uses a codice_10 parameter, and provides a codice_11 library for parsing these arguments. Example:
(command-line #:program "emoticon"
 #:once-any ; the following two are mutually exclusive
 [("-s" "--smile") "smile mode" (smile? #true)]
 [("-f" "--frown") "frown mode" (smile? #false)]
 #:once-each
 [("-n" "--nose") "add a nose" (nose? #true)]
 [("-e" "--eyes") char "use <char> for the eyes" (eyes char)])
(printf "~a~a~a\n"
 (eyes)
 (if (nose?) "-" "")
 (if (smile?) ")" "("))
The library parses long and short flags, handles arguments, allows combining short flags, and handles codice_12 and codice_13 automatically:
$ racket /tmp/c -nfe 8
8-(
Rexx.
Rexx uses codice_14, e.g.:
do i=1 to words(arg(1))
 say word(arg(1), i)
end
Node.js.
JavaScript programs written for Node.js use the codice_15 global variable.
// argv.js
console.log(process.argv);
$ node argv.js one two three four five
[ 'node',
 '/home/avian/argvdemo/argv.js',
 'one',
 'two',
 'three',
 'four',
 'five' ]
Node.js programs are invoked by running the interpreter node interpreter with a given file, so the first two arguments will be codice_16 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 codice_15.
// process-args.js
console.log(process.argv.slice(2));
$ node process-args.js one two=three four
 'one',
 'two=three',
 'four' ]