Command-line arguments

From Rosetta Code

Jump to: navigation, search
Task
Command-line arguments
You are encouraged to solve this task according to the task description, using any language you may know.
Command-line arguments is part of Short Circuit's Console Program Basics selection.
Retrieve the list of command-line arguments given to the program.

Example command line:

myprogram -c "alpha beta" -h "gamma"

Contents

[edit] Ada

Command line arguments are available through the predefined package Ada.Command_Line.

with Ada.Command_line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO
 
procedure Print_Commands is
begin
-- The number of command line arguments is retrieved from the function Argument_Count
-- The actual arguments are retrieved from the function Argument
-- The program name is retrieved from the function Command_Name
Put(Command_Name & " ");
for Arg in 1..Argument_Count loop
Put(Argument(Arg) & " ");
end loop;
New_Line;
end Print_Commands;

[edit] Aikido

The arguments are passed to the program as a vector of strings called args

 
 
foreach arg in args {
println ("arg: " + arg)
}
 
 

[edit] ALGOL 68

Works with: ALGOL 68G version Any - tested with release mk15-0.8b.fc9.i386 - argc and argv are not part of the standard's prelude

main:(
FOR i TO argc DO
printf(($"the argument #"g(-0)" is "gl$, i, argv(i)))
OD
)

Output:

the argument #1 is a68g
the argument #2 is Command_Line_Arguments.a68

[edit] AutoHotkey

From the AutoHotkey documentation: "The script sees incoming parameters as the variables %1%, %2%, and so on. In addition, %0% contains the number of parameters passed (0 if none). "

Loop %0% ; number of parameters
params .= %A_Index% . A_Space
If params !=
MsgBox, %0% parameters were passed:`n`n %params%
Else
Run, %A_AhkPath% "%A_ScriptFullPath%" -c "\"alpha beta\"" -h "\"gamma\""

[edit] BASIC

Works with: QuickBASIC

For most older BASICs that supply the keyword COMMAND$, all arguments are returned in a single string that must then be parsed inside the program. (Unlike modern BASICs, there is often no easy way to retrieve the program's name.)

PRINT "args: '"; COMMAND$; "'"

Sample output:

args: 'This is a test.'

Works with: FreeBASIC

FreeBASIC supplies three ways to retrieve the arguments: COMMAND$ (which works identically to QuickBASIC's COMMAND$), COMMAND$() (a string array which works like C's argv[]), and __FB_ARGV__ (an array of pointers which works even more like C's argv[]).

DIM i AS INTEGER
 
PRINT COMMAND$
 
PRINT "This program is named "; COMMAND$(0)
i = 1
DO WHILE(LEN(COMMAND$(i)))
PRINT "The argument "; i; " is "; COMMAND$(i)
i = i + 1
LOOP
 
FOR i = 0 TO __FB_ARGC__ - 1
PRINT "arg "; i; " = '"; *__FB_ARGV__[i]; "'"
NEXT i

Sample output:

C:\>cla 1 2 3
1 2 3
This program is named cla
The argument  1 is 1
The argument  2 is 2
The argument  3 is 3
arg  0 = 'cla'
arg  1 = '1'
arg  2 = '2'
arg  3 = '3'

See also: RapidQ

[edit] Batch File

Works with: Windows NT version 4 or later (includes Windows XP and onward)

@echo off
setlocal enabledelayedexpansion
 
set Count=0
:loop
if not "%1"=="" (
set /a count+=1
set parameter[!count!]=% class="re2">1
shift
goto loop
)
 
for /l %%a in (1,1,%count%) do (
echo !parameter[%% class="re2">a]!
)

Another way of doing it

::args2.cmd
@echo off
setlocal enabledelayedexpansion
set fn=%~f0
set p0=%~0
set p*=%*
set /a c=1
:loop
if @%1==@ goto done
set p%c%=%~1
set /a c=c+1
shift
goto loop
:done
set /a c=c-1
set p#=%c%
echo fn=%fn%
echo p0=%p0%
echo p*=%p*%
echo p#=%p#%
for /l %%i in (1,1,%p#%) do (
echo p%%i=!p%%i!
)

Invocation:

>args2 foo "bar baz" quux
fn=d:\bin\args2.cmd
p0=args2
p*=foo "bar baz" quux
p#=3
p1=foo
p2=bar baz
p3=quux
 

[edit] C

Command line arguments are passed to main. Since the program name is also passed as "argument", the provided count is actually one more than the number of program arguments. Traditionally the argument count is named argc and the array of argument strings is called argv, but that's not mandatory; any (non-reserved) name will work just as well. It is, however, a good idea to stick to the conventional names.

Be careful on systems that use Unicode or other multibyte character sets. You may need to use a type of _wchar* and multi-byte-character-set-aware versions of printf.

#include <stdio.h>
 
int main(int argc, char* argv[])
{
int i;
printf("This program is named %s.\n", argv[0]);
for (i = 1; i < argc; ++i)
printf("the argument #%d is %s\n", i, argv[i]);
 
return 0;
}

[edit] C++

Command line arguments are passed the same way as in C.

This example uses iostream. Traditional C I/O also works.

#include <iostream>
 
int main(int argc, char* argv[])
{
std::cout << "This program is named " << argv[0] << std::endl;
std::cout << "There are " << argc-1 << " arguments given." << std::endl;
for (int i = 1; i < argc; ++i)
std::cout << "the argument #" << i << " is " << argv[i] << std::endl;
 
return 0;
}

[edit] C#

There are at least two methods to access the command-line arguments. The first method is to access the string array passed to Main. This method only accesses the arguments and not the path to the executable.

using System;
 
namespace RosettaCode {
class Program {
static void Main(string[] args) {
for (int i = 0; i < args.Length; i++)
Console.WriteLine(String.Format("Argument {0} is '{1}'", i, args[i]));
}
}
}

The second method is to call the Environment.GetCommandLineArgs function. This method also returns the path to the executable as args[0] followed by the actual command line arguments.

using System;
 
namespace RosettaCode {
class Program {
static void Main() {
string[] args = Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
Console.WriteLine(String.Format("Argument {0} is '{1}'", i, args[i]));
}
}
}

[edit] Clojure

The value of *command-line-args* is a sequence of the supplied command line arguments, or nil if none were supplied.

[edit] Common Lisp

The Common Lisp standard does not specify anything relating to external invocation of a Common Lisp system. The method for getting command-line arguments varies by implementation; here are some examples:

Implementation Expression Includes program name (argv[0])
SBCL sb-ext:*posix-argv* Yes
CLISP ext:*args* No

All of these return a list of strings.

[edit] Clean

getCommandLine from the module ArgEnv returns an array of command-line arguments (the first element is the name of the program).

import ArgEnv
 
Start = getCommandLine

[edit] D

import std.stdio ;
 
void main(string[] args) {
foreach(i, e ; args[1..$])
writefln("#%2d : %s", i + 1, e) ;
}

Besides operating directly on arguments, tango provides nice command-line parser.

Library: tango

import tango.text.Arguments;
import tango.io.Stdout;
 
void main(char[][] realArgs)
{
auto args = new Arguments;
 
args("hello").required.params(1).requires("world");
args("world").params(1).aliased('w');
 
if (! args.parse(realArgs)) {
Stdout ("bad arguments");
 
} else {
Stdout("argument for --hello ") (args("hello").assigned).newline;
Stdout("argument for --world ") (args("world").assigned).newline;
}
}

sample run:

./cmdargs --hello "asdasd -w qweqwe" -w vuvuzela
argument for --hello [asdasd -w qweqwe]
argument for --world [vuvuzela]

[edit] Delphi

// The program name and the directory it was called from are in
// param[0] , so given the axample of myprogram -c "alpha beta" -h "gamma"
 
for x := 0 to paramcount do
writeln('param[',x,'] = ',param[x]);
 
// will yield ( assuming windows and the c drive as the only drive) :
 
// param[0] = c:\myprogram<br>
// param[1] = -c<br>
// param[2] = 'alpha beta'<br>
// param[3] = -h<br>
// param[0] = gama<br>

[edit] E

interp.getArgs()

[edit] Eiffel

This class inherits functionality for dealing with command line arguments from class ARGUMENTS. It uses the feature separate_character_option_value to return the values by option name for each of the two arguments.

class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Print values for arguments with options 'c' and 'h'.
do
print ("Command line argument value for option 'c' is: ")
print (separate_character_option_value ('c') + "%N")
print ("Command line argument value for option 'h' is: ")
print (separate_character_option_value ('h') + "%N")
io.read_line -- Keep console window open
end
end

Output (for command line arguments: -c "alpha beta" -h "gamma"):

Command line argument value for option 'c' is: alpha beta
Command line argument value for option 'h' is: gamma

[edit] Erlang

3> init:get_arguments().

result

[{root,["/usr/erlang/erl5.5"]},
{progname,["erl"]},
{home,["/home/me"]},
{c,["alpha beta"]},
{h,["gamma"]}]

init:get_argument(name) can be used to fetch value of a particular flag

4> init:get_argument(h).
{ok,[["gamma"]]}
5> init:get_argument(c).
{ok,[["alpha beta"]]}

[edit] F#

The entry-point function accepts the comment line arguments as an array of strings. The following program will print each argument on a separate line.

#light
[<EntryPoint>]
let main args =
Array.iter (fun x -> printfn "%s" x) args
0

[edit] Factor

USING: io sequences command-line ;
(command-line) [ print ] each

[edit] Forth

Access to command line arguments is not a standard feature of Forth, since it is designed to be used without an operating system. The popular GNU implementation gforth runs from a shell and can access command line arguments similar to C: variable argc contains the count (including the command itself) and arg is a function that returns the nth argument as a string.

Works with: gforth version 0.6.2

\ args.f: print each command line argument on a separate line
: main
argc @ 0 do i arg type cr loop ;
 
main bye

Here is output from a sample run.

$ gforth args.f alpha "beta gamma" delta
gforth
args.f
alpha
beta gamma
delta
$

[edit] Fortran

Works with: Fortran version 90 and later

program command_line_arguments
 
implicit none
integer, parameter :: len_max = 256
integer :: i
character (len_max) :: arg
 
do i = 0, iargc ()
call getarg (i, arg)
write (*, '(a)') trim (arg)
end do
 
end program command_line_arguments
 

Note: iargc and getarg are common extensions that are implemented by e.g. the Intel Fortran Compiler, G95 and gfortran.

Sample usage:

> ./a.out -c "alpha beta" -h "gamma"
./a.out
-c
alpha beta
-h
gamma

[edit] Go

package main
import (
"fmt"
"os"
)
 
func main() {
for i, x := range os.Args {
if i == 0 {
fmt.Printf("This program is named %s.\n", x)
} else {
fmt.Printf("the argument #%d is %s\n", i, x)
}
}
}

[edit] Groovy

Command-line arguments are accessible via the args list variable. The following is saved as the file "Echo.groovy":

println args

The existence of command-line arguments presupposes the existence of a command line interpreter. The following test runs were entered in a cygwin bash shell in a Microsoft Windows XP system:

$ groovy Echo this is an argument list
[this, is, an, argument, list]
$ groovy Echo -x alkfrew4oij -cdkjei +22
[-x, alkfrew4oij, -cdkjei, +22]
$

For more sophisticated command-line option and option-argument parsing use the CliBuilder (command-line interface builder) library, which extends the functionality of the Java-based Apache Commons CLI library to Groovy.

[edit] Haskell

Defined by the System module, getArgs :: IO [String] provides the command-line arguments in a list.

myprog.hs:

import System
main = getArgs >>= print
myprog a -h b c
=> ["a","-h","b","c"]

[edit] HicEst

DO i = 2, 100 ! 1 is HicEst.exe
EDIT(Text=$CMD_LINE, SePaRators='-"', ITeM=i, IF ' ', EXit, ENDIF, Parse=cmd, GetPosition=position)
IF(position > 0) WRITE(Messagebox) cmd
ENDDO

[edit] Icon and Unicon

[edit] Icon

Command line parameters are passed to Icon/Unicon programs as a list of strings.

procedure main(arglist)
every write(!arglist)
end

Library: Icon Programming Library includes options that parses the command line as switches and arguments and returns the results in a table.

[edit] Unicon

This Icon solution works in Unicon.

[edit] Ioke

System programArguments each(println)

[edit] J

The global ARGV holds the command line arguments.

[edit] Java

public class Arguments {
public static void main(String[] args) {
System.out.println("There are " + args.length + " arguments given.");
for(int i = 0; i < args.length; i++)
System.out.println("The argument #" + (i+1) + " is " + args[i] + "and is at index " + i);
}
}

For more sophisticated command-line option and option-argument parsing use the Apache Commons CLI (command-line interface) library.

[edit] JavaScript

Works with: JScript

var objArgs = WScript.Arguments;
for (var i = 0; i < objArgs.length; i++)
WScript.Echo(objArgs.Item(i));

Works with: Rhino Works with: SpiderMonkey

for (var i = 0; i < arguments.length; i++)
print(arguments[i]);

[edit] Liberty BASIC

print CommandLine$

[edit] Logo

Works with: UCB Logo version 5.6 If the command line to a logo script is written

logo file.logo - arg1 arg2 arg3

Then the arguments after the "-" are found in a list in variable :COMMAND.LINE

show :COMMAND.LINE
[arg1 arg2 arg3]

Alternatively, make the first line of an executable logo script:

#! /usr/bin/logo -

to be able to invoke the script with arguments.

file.logo arg1 arg2 arg3

[edit] LSE64

argc , nl  # number of arguments (including command itself)
0 # argument
dup arg dup 0 = || ,t 1 + repeat
drop

[edit] MMIX

argv   IS    $1
argc IS $0
i IS $2
 
LOC #100
Main LOC @
SETL i,1 % i = 1
Loop CMP $3,argc,2 % argc < 2 ?
BN $3,1F % then jump to end
XOR $255,$255,$255 % clear $255
8ADDU $255,i,argv % i*8 + argv
LDOU $255,$255,0 % argv[i]
TRAP 0,Fputs,StdOut % write the argument
GETA $255,NewLine % add a newline
TRAP 0,Fputs,StdOut
INCL i,1 % increment index
SUB argc,argc,1 % argc--
BP argc,Loop % argc > 0? then Loop
1H LOC @
XOR $255,$255,$255 % exit(0)
TRAP 0,Halt,0
 
NewLine BYTE #a,0

[edit] Modula-3

Command line parameters are accessed using the Params module.

MODULE Args EXPORTS Main;
 
IMPORT IO, Params;
 
BEGIN
IO.Put(Params.Get(0) & "\n");
IF Params.Count > 1 THEN
FOR i := 1 TO Params.Count - 1 DO
IO.Put(Params.Get(i) & "\n");
END;
END;
END Args.

Output:

martin@thinkpad:~$ ./prog
./prog
martin@thinkpad:~$ ./prog 10
./prog
10
martin@thinkpad:~$ ./prog 10 20
./prog
10
20

[edit] Objective-C

In addition to the regular C mechanism of arguments to main(), Objective-C also has another way to get the arguments as string objects inside an array object:

NSArray *args = [[NSProcessInfo processInfo] arguments];
NSLog(@"This program is named %@.", [args objectAtIndex:0]);
NSLog(@"There are %d arguments.", [args count] - 1);
for (i = 1; i < [args count]; ++i){
NSLog(@"the argument #%d is %@", i, [args objectAtIndex:i]);
}

[edit] Objeck

 
bundle Default {
class Line {
function : Main(args : String[]) ~ Nil {
for(i := 0; i < args->GetSize(); i := i + 1;) {
args[i]->PrintLine();
};
}
}
}
 

[edit] OCaml

The program name is also passed as "argument", so the array length is actually one more than the number of program arguments.

let () =
Printf.printf "This program is named %s.\n" Sys.argv.(0);
for i = 1 to Array.length Sys.argv - 1 do
Printf.printf "the argument #%d is %s\n" i Sys.argv.(i)
done

[edit] Using the Arg module

(* default values *)
let somebool = ref false
let somestr = ref ""
let someint = ref 0
 
let usage = "usage: " ^ Sys.argv.(0) ^ " [-b] [-s string] [-d int]"
 
let speclist = [
("-b", Arg.Unit (fun () -> somebool := true), ": set somebool to true");
("-s", Arg.String (fun s -> somestr := s), ": what follows -s sets some string");
("-d", Arg.Int (fun d -> someint := d), ": some int parameter");
]
 
let () =
(* Read the arguments *)
Arg.parse
speclist
(fun x -> raise (Arg.Bad ("Bad argument : " ^ x)))
usage;
 
Printf.printf " %b %d '%s'\n" !somebool !someint !somestr;
;;


% ocaml arg.ml --help
usage: tmp.ml [-b] [-s string] [-d int]
  -b : set somebool to true
  -s : what follows -s sets some string
  -d : some int parameter
  --help  Display this list of options

% ocaml arg.ml -d 4 -b -s blabla
 true 4 'blabla'

% ocaml arg.ml
 false 0 ''

[edit] Oz

[edit] Raw arguments

Like in C, but without the program name:

functor
import Application System
define
ArgList = {Application.getArgs plain}
{ForAll ArgList System.showInfo}
{Application.exit 0}
end

[edit] Preprocessed arguments

functor
import Application System
define
ArgSpec =
record(
c(type:string single %% option "--c" expects a string, may only occur once,
optional:false char:&c) %% is not optional and has a shortcut "-c"
 
h(type:string single %% option "--h" expects a string, may only occur once,
default:"default h" %% is optional and has a default value if not given
char:&h) %% and has a shortcut "-h"
)
Args = {Application.getArgs ArgSpec}
{System.showInfo Args.c}
{System.showInfo Args.h}
{Application.exit 0}
end

[edit] Perl

Works with: Perl version 5.x @ARGV is the array containing all command line parameters

my @params = @ARGV;
my $second = $ARGV[1];
my $fifth = $ARGV[4];

[edit] Perl 6

Perl 5's @ARGV is available as @*ARGS. Alternatively, if you define a subroutine named MAIN, Perl will automatically process @*ARGS according to Unix conventions and MAIN's signature (or signatures, if your MAIN is a multi sub) and then call MAIN with appropriate arguments; see Synopsis 6.

[edit] PHP

When PHP is run from the command line, the special variables $argv and $argc contain the array of arguments, and the number of arguments, respectively. The program name is passed as the first argument.

<?php
$program_name = $argv[0];
$second_arg = $argv[2];
?>

[edit] PL/I

 
/* The entire command line except the command word itself is passed */
/* to the parameter variable in PL/I. */
program: procedure (command_line) options (main);
declare command_line character (100) varying;
 
...
 
end program;
 

[edit] PicoLisp

There are three ways to handle command-line arguments in PicoLisp:

1. Obtain all arguments as a list of strings via 'argv'

2. Fetch each argument individually with 'opt'

3. Use the built-in command-line interpretation, where arguments starting with a hypen are executed as functions.

Here we use the third option, as it is not so obvious, sometimes more flexible, and in fact the most commonly used one for application development.

We define 'c' and 'h' as functions, which retrieve their argument with 'opt', and then 'load' all remaining command line arguments.

#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(de c ()
(prinl "Got 'c': " (opt)) )
 
(de h ()
(prinl "Got 'h': " (opt)) )
 
(load T)
(bye)

Output:

$ ./myprogram -c "alpha beta" -h "gamma"
Got 'c': alpha beta
Got 'h': gamma

[edit] Pop11

variable poparglist contains list of command line arguments (as strings). One can use iteration over list to process then (for example print).

lvars arg;
for arg in poparglist do
printf(arg, '->%s<-\n');
endfor;

[edit] PowerShell

In PowerShell the arguments to a script can be accessed with the $args array:

$i = 0
foreach ($s in $args) {
Write-Host Argument (++$i) is $s
}

[edit] PureBasic

[edit] Reading all parameters

You can easily read all parameters by using ProgramParameter() without argument.

If OpenConsole()
Define n=CountProgramParameters()
PrintN("Reading all parameters")
While n
PrintN(ProgramParameter())
n-1
Wend
Print(#CRLF$+"Press Enter")
Input()
CloseConsole()
EndIf

[edit] Reading specific parameters

You can specify which parameter 'n' to read.

If OpenConsole()
Define n
PrintN("Reading specific pameters")
For n=0 To CountProgramParameters()
PrintN(ProgramParameter(n))
Next
Print(#CRLF$+"Press Enter")
Input()
CloseConsole()
EndIf

[edit] Python

sys.argv is a list containing all command line arguments, including the program name. Typically you slice the list to access the actual command line argument:

import sys
program_name = sys.argv[0]
arguments = sys.argv[1:]
count = len(arguments)

When running a module by invoking Python, the Python interpreter processes and removes some of the arguments, and the module cannot access them. To process command line arguments, run the module directly. sys.argv is a copy of the command line arguments; modifying sys.argv will not change the arguments seen by other processes, e.g. ps. (In other words sys.argv is an object which contains a copy of the process' command line arguments ... modifying that copy is only visible from within the Python program and not externally).

For powerful option parsing capabilities check out the optparse module.

[edit] R

Since you do not create executables using R, the task is not directly appropriate. It is however possible to determine the list of arguments supplied when the R session was invoked.

commandArgs(TRUE)

[edit] RapidQ

PRINT "This program is named "; Command$(0)
FOR i=1 TO CommandCount
PRINT "The argument "; i; " is "; Command$(i)
NEXT i

[edit] Raven

ARGS print
 
stack (6 items)
0 => "raven"
1 => "myprogram"
2 => "-c"
3 => "alpha beta"
4 => "-h"
5 => "gamma"

[edit] Ruby

Command line arguments are available in the constant Object::ARGV.

myprog:

#! /usr/bin/env ruby
p ARGV
 myprog a -h b c
 => ["a","-h","b","c"]

[edit] Sather

class MAIN is
main(args:ARRAY{STR}) is
loop
#OUT + args.elt! + "\n";
end;
end;
end;

As in C (and others), the first element is the command itself (exactly as it is written in the command line and after shell variable expansion); e.g.

$ /home/home/rosetta/sather/a.out arg1 arg2 arg3

prints

/home/home/rosetta/sather/a.out
arg1
arg2
arg3

[edit] Scala

Calling Scala from command line means invoking a method called main, defined on an object, whose type is (Array[String])Unit, meaning it receives an array of strings, and returns unit. That array contains the command line arguments.

object T {
def main(args: Array[String]) {
println("Received the following arguments": + args.mkString("", ", ", "."))
}
}

When running a Scala script, where the whole body is executed, the arguments get stored in an array of strings called argv:

println("My arguments are: "+argv.mkString("", ", ", "."))

[edit] Scheme

Works with: Chicken Scheme

COMMAND-LINE-ARGUMENTS returns a list of the arguments.

$ csi -e "(display (command-line-arguments)) (newline)"
(-e (display (command-line-arguments)) (newline))

[edit] Seed7

$ include "seed7_05.s7i";
 
const proc: main is func
local
var integer: i is 0;
begin
writeln("This program is named " <& name(PROGRAM) <& ".");
for i range 1 to length(argv(PROGRAM)) do
writeln("The argument #" <& i <& " is " <& argv(PROGRAM)[i]);
end for;
end func;

[edit] Slate

StartupArguments do: [| :arg | inform: arg]

[edit] Smalltalk

Works with: GNU Smalltalk

(1 to: Smalltalk getArgc) do: [ :i |
(Smalltalk getArgv: i) displayNl
]

[edit] Standard ML

print ("This program is named " ^ CommandLine.name () ^ ".\n");
val args = CommandLine.arguments ();
Array.appi
(fn (i, x) => print ("the argument #" ^ Int.toString (i+1) ^ " is " ^ x ^ "\n"))
(Array.fromList args);

[edit] Tcl

The predefined variable argc contains the number of arguments passed to the routine, argv contains the arguments as a list. Retrieving the second argument might look something like this:

if { $argc > 1 } {
puts [lindex $argv 1]
}

(Tcl counts from zero, thus [lindex $list 1] retrieves the second item in the list)

[edit] Toka

Arguments are stored into an array. The first element in the array is the name of the program, the rest are the arguments in order. The number of arguments is provided by #args.

[ arglist array.get type cr ] is show-arg
[ dup . char: = emit space ] is #=
1 #args [ i #= show-arg ] countedLoop

[edit] UNIX Shell

[edit] Bourne Shell

To retrieve the entire list of arguments:

WHOLELIST="$@"

To retrieve the second and fifth arguments:

SECOND=$2
FIFTH=$5

[edit] Ursala

Command line arguments are accessible to an application through a data structure initialized by the run-time system. This example application does nothing but display the data structure on standard output.

#import std
 
#executable ('parameterized','')
 
clarg = <.file$[contents: --<''>+ _option%LP]>+ ~command.options

Here is a bash terminal session.

$ clarg -c alpha,beta -h gamma --foo=bar,baz
<
   option[
      keyword: 'c',
      parameters: <'alpha','beta'>],
   option[
      position: 1,
      keyword: 'h',
      parameters: <'gamma'>],
   option[
      position: 2,
      longform: true,
      keyword: 'foo',
      parameters: <'bar','baz'>]>

[edit] V

The arguments to the program are stored in the stack,

args.v

$stack puts
 
./args.v a b c
=[args.v a b c]

[edit] Visual Basic .NET

This syntax will tokenize the command line arguments. Tokens are normally delimited by spaces, but spaces can be part of a token if surrounded by quotes.

Sub Main(ByVal args As String())
For Each token In args
Console.WriteLine(token)
Next
End Sub
Personal tools
Support