Command-line arguments: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 11: Line 11:
=={{header|11l}}==
=={{header|11l}}==
<code>:argv</code> is a list containing all command line arguments, including the program name.
<code>:argv</code> is a list containing all command line arguments, including the program name.
<lang 11l>:start:
<syntaxhighlight lang="11l">:start:
print(‘Program name: ’:argv[0])
print(‘Program name: ’:argv[0])
print("Arguments:\n":argv[1..].join("\n"))</lang>
print("Arguments:\n":argv[1..].join("\n"))</syntaxhighlight>


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==
Line 25: Line 25:
everything CP/M gives it.
everything CP/M gives it.


<lang 8080asm>putch: equ 2 ; CP/M syscall to print character
<syntaxhighlight lang="8080asm">putch: equ 2 ; CP/M syscall to print character
puts: equ 9 ; CP/M syscall to print $-terminated string
puts: equ 9 ; CP/M syscall to print $-terminated string
arglen: equ 80h ; Length of argument
arglen: equ 80h ; Length of argument
Line 70: Line 70:
cmdln: db 'Command line: $'
cmdln: db 'Command line: $'
file1: db 13,10,'File 1: $'
file1: db 13,10,'File 1: $'
file2: db 13,10,'File 2: $'</lang>
file2: db 13,10,'File 2: $'</syntaxhighlight>


{{out}}
{{out}}
Line 98: Line 98:
In Ada95 and later versions, command line arguments are available through the predefined package Ada.Command_Line. In Ada83, this would be implementation dependent.
In Ada95 and later versions, command line arguments are available through the predefined package Ada.Command_Line. In Ada83, this would be implementation dependent.


<lang ada>with Ada.Command_line; use Ada.Command_Line;
<syntaxhighlight lang="ada">with Ada.Command_line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO; use Ada.Text_IO;


Line 111: Line 111:
end loop;
end loop;
New_Line;
New_Line;
end Print_Commands;</lang>
end Print_Commands;</syntaxhighlight>


=== Alternative version using Matreshka ===
=== Alternative version using Matreshka ===
Line 117: Line 117:
Uses [http://forge.ada-ru.org/matreshka Matreshka]
Uses [http://forge.ada-ru.org/matreshka Matreshka]


<lang ada>with Ada.Wide_Wide_Text_IO;
<syntaxhighlight lang="ada">with Ada.Wide_Wide_Text_IO;


with League.Application;
with League.Application;
Line 128: Line 128:
(League.Application.Arguments.Element (J).To_Wide_Wide_String);
(League.Application.Arguments.Element (J).To_Wide_Wide_String);
end loop;
end loop;
end Main;</lang>
end Main;</syntaxhighlight>


=={{header|Aikido}}==
=={{header|Aikido}}==
The arguments are passed to the program as a vector of strings called <em>args</em>
The arguments are passed to the program as a vector of strings called <em>args</em>
<lang aikido>
<syntaxhighlight lang="aikido">


foreach arg in args {
foreach arg in args {
Line 138: Line 138:
}
}


</syntaxhighlight>
</lang>


=={{header|Aime}}==
=={{header|Aime}}==
<lang aime>integer i;
<syntaxhighlight lang="aime">integer i;


i = 0;
i = 0;
Line 148: Line 148:
o_byte('\n');
o_byte('\n');
i += 1;
i += 1;
}</lang>
}</syntaxhighlight>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386 - ''argc'' and ''argv'' are not part of the standard's prelude}}
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386 - ''argc'' and ''argv'' are not part of the standard's prelude}}
<lang algol68>main:(
<syntaxhighlight lang="algol68">main:(
FOR i TO argc DO
FOR i TO argc DO
printf(($"the argument #"g(-0)" is "gl$, i, argv(i)))
printf(($"the argument #"g(-0)" is "gl$, i, argv(i)))
OD
OD
)</lang>
)</syntaxhighlight>
Linux command:
Linux command:
/usr/bin/a68g Command-line_arguments.a68 - 1 2 3 ...
/usr/bin/a68g Command-line_arguments.a68 - 1 2 3 ...
Line 172: Line 172:
<p>The main function "main(argv,argc)" is a macro-defined in HOPPER.H: get the arguments, and put them into array ARGV; ARGC have total arguments.</p>
<p>The main function "main(argv,argc)" is a macro-defined in HOPPER.H: get the arguments, and put them into array ARGV; ARGC have total arguments.</p>
<p>Macro MAIN(ARGV, ARGC):</p>
<p>Macro MAIN(ARGV, ARGC):</p>
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#defn main(_V_,_N_) #RAND, main:, V#RNDV=1,_V_={#VOID}, \
#defn main(_V_,_N_) #RAND, main:, V#RNDV=1,_V_={#VOID}, \
_N_=0,totalarg,mov(_N_), \
_N_=0,totalarg,mov(_N_), \
LOOPGETARG_#RNDV:, {[ V#RNDV ]},push(_V_),++V#RNDV,\
LOOPGETARG_#RNDV:, {[ V#RNDV ]},push(_V_),++V#RNDV,\
{_N_,V#RNDV},jle(LOOPGETARG_#RNDV),clear(V#RNDV)
{_N_,V#RNDV},jle(LOOPGETARG_#RNDV),clear(V#RNDV)
</syntaxhighlight>
</lang>
VERSION 1:
VERSION 1:
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#include <hopper.h>
#include <hopper.h>


Line 188: Line 188:
next
next
exit(0)
exit(0)
</syntaxhighlight>
</lang>
VERSION 2:
VERSION 2:
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#include <hopper.h>
#include <hopper.h>


Line 201: Line 201:
++i,{argc,i}jle(__CNT_ARGS__)
++i,{argc,i}jle(__CNT_ARGS__)
exit(0)
exit(0)
</syntaxhighlight>
</lang>
VERSION 3:
VERSION 3:
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#include <hopper.h>
#include <hopper.h>


Line 216: Line 216:
}
}
exit(0)
exit(0)
</syntaxhighlight>
</lang>
VERSION 4:
VERSION 4:
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#include <natural.h>
#include <natural.h>
#include <hopper.h>
#include <hopper.h>
Line 231: Line 231:
remember ( argument 'i' ); put a new line and print it; finally increment 'i' ).
remember ( argument 'i' ); put a new line and print it; finally increment 'i' ).
exit(0)
exit(0)
</syntaxhighlight>
</lang>
ETCETERA...
ETCETERA...
{{out}}
{{out}}
Line 244: Line 244:
=={{header|AppleScript}}==
=={{header|AppleScript}}==


<lang applescript>
<syntaxhighlight lang="applescript">
#!/usr/bin/env osascript
#!/usr/bin/env osascript
-- Print first argument
-- Print first argument
Line 250: Line 250:
return (item 1 of argv)
return (item 1 of argv)
end run
end run
</syntaxhighlight>
</lang>


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
/* program commandLine.s */
/* program commandLine.s */
Line 317: Line 317:
bx lr @ return
bx lr @ return


</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>loop arg 'a [
<syntaxhighlight lang="rebol">loop arg 'a [
print a
print a
]</lang>
]</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
From the AutoHotkey [http://www.autohotkey.com/docs/Scripts.htm documentation]:
From the AutoHotkey [http://www.autohotkey.com/docs/Scripts.htm 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). "
"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). "
<lang autohotkey>Loop %0% ; number of parameters
<syntaxhighlight lang="autohotkey">Loop %0% ; number of parameters
params .= %A_Index% . A_Space
params .= %A_Index% . A_Space
If params !=
If params !=
MsgBox, %0% parameters were passed:`n`n %params%
MsgBox, %0% parameters were passed:`n`n %params%
Else
Else
Run, %A_AhkPath% "%A_ScriptFullPath%" -c "\"alpha beta\"" -h "\"gamma\""</lang>
Run, %A_AhkPath% "%A_ScriptFullPath%" -c "\"alpha beta\"" -h "\"gamma\""</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==


<lang awk>#!/usr/bin/awk -f
<syntaxhighlight lang="awk">#!/usr/bin/awk -f


BEGIN {
BEGIN {
Line 343: Line 343:
print "Argument " l " is " ARGV[l]
print "Argument " l " is " ARGV[l]
}
}
}</lang>
}</syntaxhighlight>


=={{header|Babel}}==
=={{header|Babel}}==
Invoke Babel in interactive mode with arguments using the -i switch:
Invoke Babel in interactive mode with arguments using the -i switch:


<lang babel>babel -i Larry Mo Curly</lang>
<syntaxhighlight lang="babel">babel -i Larry Mo Curly</syntaxhighlight>


Print the argv list with newlines:
Print the argv list with newlines:


<lang babel>argv prn !</lang>
<syntaxhighlight lang="babel">argv prn !</syntaxhighlight>


{{out}}
{{out}}
Line 362: Line 362:
Print the argv list with spaces:
Print the argv list with spaces:


<lang babel>argv prs !</lang>
<syntaxhighlight lang="babel">argv prs !</syntaxhighlight>


{{out}}
{{out}}
Line 369: Line 369:
To access an individual argument, use the ith operator to select an element from the argv list; print with newline using say:
To access an individual argument, use the ith operator to select an element from the argv list; print with newline using say:


<lang babel>argv 1 ith say !</lang>
<syntaxhighlight lang="babel">argv 1 ith say !</syntaxhighlight>


{{out}}
{{out}}
Line 380: Line 380:
For most older BASICs that supply the keyword <code>COMMAND$</code>, 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.)
For most older BASICs that supply the keyword <code>COMMAND$</code>, 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.)


<lang qbasic>PRINT "args: '"; COMMAND$; "'"</lang>
<syntaxhighlight lang="qbasic">PRINT "args: '"; COMMAND$; "'"</syntaxhighlight>


Sample output:
Sample output:
Line 389: Line 389:
FreeBASIC supplies three ways to retrieve the arguments: <code>COMMAND$</code> (which works identically to QuickBASIC's <code>COMMAND$</code>), <code>COMMAND$()</code> (a string array which works like [[#C|C]]'s <code>argv[]</code>), and <code>__FB_ARGV__</code> (an array of pointers which works even more like C's <code>argv[]</code>) and __FB_ARGC__ (which works like C's <code>argc</code>).
FreeBASIC supplies three ways to retrieve the arguments: <code>COMMAND$</code> (which works identically to QuickBASIC's <code>COMMAND$</code>), <code>COMMAND$()</code> (a string array which works like [[#C|C]]'s <code>argv[]</code>), and <code>__FB_ARGV__</code> (an array of pointers which works even more like C's <code>argv[]</code>) and __FB_ARGC__ (which works like C's <code>argc</code>).


<lang freebasic>DIM i AS INTEGER
<syntaxhighlight lang="freebasic">DIM i AS INTEGER


PRINT COMMAND$
PRINT COMMAND$
Line 402: Line 402:
FOR i = 0 TO __FB_ARGC__ - 1
FOR i = 0 TO __FB_ARGC__ - 1
PRINT "arg "; i; " = '"; *__FB_ARGV__[i]; "'"
PRINT "arg "; i; " = '"; *__FB_ARGV__[i]; "'"
NEXT i</lang>
NEXT i</syntaxhighlight>


Sample output:
Sample output:
Line 417: Line 417:


==={{header|BaCon}}===
==={{header|BaCon}}===
<lang freebasic>' Command line arguments including program name
<syntaxhighlight lang="freebasic">' Command line arguments including program name
PRINT "Entire command line: ", ARGUMENT$
PRINT "Entire command line: ", ARGUMENT$


Line 425: Line 425:
PRINT " " & cli$[i];
PRINT " " & cli$[i];
NEXT
NEXT
PRINT</lang>
PRINT</syntaxhighlight>


{{out}}
{{out}}
Line 440: Line 440:
=={{header|Batch File}}==
=={{header|Batch File}}==
{{works with|Windows NT|4 or later (includes Windows XP and onward)}}
{{works with|Windows NT|4 or later (includes Windows XP and onward)}}
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
setlocal enabledelayedexpansion


Line 454: Line 454:
for /l %%a in (1,1,%count%) do (
for /l %%a in (1,1,%count%) do (
echo !parameter[%%a]!
echo !parameter[%%a]!
)</lang>
)</syntaxhighlight>


Another way of doing it
Another way of doing it


<lang dos>::args2.cmd
<syntaxhighlight lang="dos">::args2.cmd
@echo off
@echo off
setlocal enabledelayedexpansion
setlocal enabledelayedexpansion
Line 480: Line 480:
for /l %%i in (1,1,%p#%) do (
for /l %%i in (1,1,%p#%) do (
echo p%%i=!p%%i!
echo p%%i=!p%%i!
)</lang>
)</syntaxhighlight>


Invocation:
Invocation:


<lang dos>>args2 foo "bar baz" quux
<syntaxhighlight lang="dos">>args2 foo "bar baz" quux
fn=d:\bin\args2.cmd
fn=d:\bin\args2.cmd
p0=args2
p0=args2
Line 492: Line 492:
p2=bar baz
p2=bar baz
p3=quux
p3=quux
</syntaxhighlight>
</lang>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic>PRINT @cmd$</lang>
<syntaxhighlight lang="bbcbasic">PRINT @cmd$</syntaxhighlight>


=={{header|Blue}}==
=={{header|Blue}}==
Line 502: Line 502:
Linux/x86-64
Linux/x86-64


<lang blue>
<syntaxhighlight lang="blue">
global _start
global _start


Line 533: Line 533:
bye
bye
;
;
</syntaxhighlight>
</lang>


=={{header|BQN}}==
=={{header|BQN}}==
BQN has a system value for getting pre-parsed command line arguments.
BQN has a system value for getting pre-parsed command line arguments.


<lang>•Show •args</lang>
<syntaxhighlight lang="text">•Show •args</syntaxhighlight>


should show the full list of args.
should show the full list of args.
Line 544: Line 544:
=={{header|Bracmat}}==
=={{header|Bracmat}}==
When Bracmat is started with one or more arguments, each argument is evaluated as if it were a Bracmat expression <i>unless</i> an argument (for example the first one) consumes the next argument(s) by calling <code>arg$</code>. Each invocation of <code>arg$</code> pops one argument from the remaining list of arguments. Calling <code>arg$</code> when no more arguments are available results in failure. The following program iterates over all arguments following the currently evaluated argument and outputs the argument to standard output.
When Bracmat is started with one or more arguments, each argument is evaluated as if it were a Bracmat expression <i>unless</i> an argument (for example the first one) consumes the next argument(s) by calling <code>arg$</code>. Each invocation of <code>arg$</code> pops one argument from the remaining list of arguments. Calling <code>arg$</code> when no more arguments are available results in failure. The following program iterates over all arguments following the currently evaluated argument and outputs the argument to standard output.
<lang>whl'(arg$:?a&out$(str$("next arg=" !a)))</lang>
<syntaxhighlight lang="text">whl'(arg$:?a&out$(str$("next arg=" !a)))</syntaxhighlight>
Now run Bracmat with this program as the first argument in a DOS environment:
Now run Bracmat with this program as the first argument in a DOS environment:
<pre>bracmat "whl'(arg$:?a&out$(str$(\"next arg=\" !a)))" "a" /b -c 2+3 'd;' "out$(\"13+7=\" 13+7)"</pre>
<pre>bracmat "whl'(arg$:?a&out$(str$(\"next arg=\" !a)))" "a" /b -c 2+3 'd;' "out$(\"13+7=\" 13+7)"</pre>
Line 576: Line 576:
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.
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.


<lang c>#include <stdlib.h>
<syntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>


Line 586: Line 586:
(void) printf("the argument #%d is %s\n", i, argv[i]);
(void) printf("the argument #%d is %s\n", i, argv[i]);
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|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.
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.
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


namespace RosettaCode {
namespace RosettaCode {
Line 599: Line 599:
}
}
}
}
}</lang>
}</syntaxhighlight>


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.
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.
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


namespace RosettaCode {
namespace RosettaCode {
Line 612: Line 612:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
Line 619: Line 619:
This example uses iostream. Traditional C I/O also works.
This example uses iostream. Traditional C I/O also works.


<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


int main(int argc, char* argv[])
int main(int argc, char* argv[])
Line 629: Line 629:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|Clean}}==
=={{header|Clean}}==
<tt>getCommandLine</tt> from the module <tt>ArgEnv</tt> returns an array of command-line arguments (the first element is the name of the program).
<tt>getCommandLine</tt> from the module <tt>ArgEnv</tt> returns an array of command-line arguments (the first element is the name of the program).


<lang clean>import ArgEnv
<syntaxhighlight lang="clean">import ArgEnv


Start = getCommandLine</lang>
Start = getCommandLine</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
Line 642: Line 642:
The value of ''*command-line-args*'' is a sequence of the supplied command line arguments, or ''nil'' if none were supplied.
The value of ''*command-line-args*'' is a sequence of the supplied command line arguments, or ''nil'' if none were supplied.


<lang Clojure>(dorun (map println *command-line-args*))</lang>
<syntaxhighlight lang="clojure">(dorun (map println *command-line-args*))</syntaxhighlight>


=={{header|CLU}}==
=={{header|CLU}}==
Line 652: Line 652:
Note that unlike C, the program name itself is not included in the list of arguments.
Note that unlike C, the program name itself is not included in the list of arguments.


<lang clu>% This program needs to be merged with PCLU's "useful.lib",
<syntaxhighlight lang="clu">% This program needs to be merged with PCLU's "useful.lib",
% where get_argv lives.
% where get_argv lives.
%
%
Line 665: Line 665:
stream$putl(po, "arg: " || arg)
stream$putl(po, "arg: " || arg)
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>$ ./cmdline -c "alpha beta" -h "gamma"
<pre>$ ./cmdline -c "alpha beta" -h "gamma"
Line 680: Line 680:


Getting the arguments in one go, exactly as they were passed in:
Getting the arguments in one go, exactly as they were passed in:
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. accept-all-args.
PROGRAM-ID. accept-all-args.
Line 693: Line 693:
GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


Getting the arguments one at a time, with arguments being split by whitespace if not in quotes:
Getting the arguments one at a time, with arguments being split by whitespace if not in quotes:
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. accept-args-one-at-a-time.
PROGRAM-ID. accept-args-one-at-a-time.
Line 712: Line 712:
GOBACK
GOBACK
.</lang>
.</syntaxhighlight>


Passing arguments from UNIX/Linux Systems to COBOL.
Passing arguments from UNIX/Linux Systems to COBOL.
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
{{works with|gnuCOBOL}}
{{works with|gnuCOBOL}}
<lang cobol>
<syntaxhighlight lang="cobol">
*>Created By Zwiegnet 8/19/2004
*>Created By Zwiegnet 8/19/2004


Line 774: Line 774:
STOP RUN.
STOP RUN.


.</lang>
.</syntaxhighlight>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
{{works with|Node.js}}
{{works with|Node.js}}
<lang coffeescript>
<syntaxhighlight lang="coffeescript">
console.log arg for arg in process.argv
console.log arg for arg in process.argv
</syntaxhighlight>
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 788: Line 788:
The following function could be used to create a uniform way to access the arguments:
The following function could be used to create a uniform way to access the arguments:


<lang lisp>(defun argv ()
<syntaxhighlight lang="lisp">(defun argv ()
(or
(or
#+clisp (ext:argv)
#+clisp (ext:argv)
Line 799: Line 799:
#+allegro (sys:command-line-arguments)
#+allegro (sys:command-line-arguments)
#+lispworks sys:*line-arguments-list*
#+lispworks sys:*line-arguments-list*
nil))</lang>
nil))</syntaxhighlight>


=={{header|Cowgol}}==
=={{header|Cowgol}}==
Line 805: Line 805:
The manner in which arguments are parsed is, however, dependent on the operating system.
The manner in which arguments are parsed is, however, dependent on the operating system.


<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";
include "argv.coh";
include "argv.coh";


Line 819: Line 819:
print(arg);
print(arg);
print("'\n");
print("'\n");
end loop;</lang>
end loop;</syntaxhighlight>


{{out}}
{{out}}
Line 838: Line 838:


=={{header|D}}==
=={{header|D}}==
<lang d>void main(in string[] args) {
<syntaxhighlight lang="d">void main(in string[] args) {
import std.stdio;
import std.stdio;


foreach (immutable i, arg; args[1 .. $])
foreach (immutable i, arg; args[1 .. $])
writefln("#%2d : %s", i + 1, arg);
writefln("#%2d : %s", i + 1, arg);
}</lang>
}</syntaxhighlight>


=={{header|Dart}}==
=={{header|Dart}}==
<lang csharp>main(List<String> args) {
<syntaxhighlight lang="csharp">main(List<String> args) {
for(var arg in args)
for(var arg in args)
print(arg);
print(arg);
}</lang>
}</syntaxhighlight>


=={{header|DCL}}==
=={{header|DCL}}==
case is not preserved unless the parameter is in quotes
case is not preserved unless the parameter is in quotes
<lang DCL>$ i = 1
<syntaxhighlight lang="dcl">$ i = 1
$ loop:
$ loop:
$ write sys$output "the value of P''i' is ", p'i
$ write sys$output "the value of P''i' is ", p'i
$ i = i + 1
$ i = i + 1
$ if i .le. 8 then $ goto loop</lang>
$ if i .le. 8 then $ goto loop</syntaxhighlight>
{{out}}
{{out}}
<pre>$ @command_line_arguments -c "alpha beta" -h "gamma"
<pre>$ @command_line_arguments -c "alpha beta" -h "gamma"
Line 871: Line 871:
=={{header|Delphi}}==
=={{header|Delphi}}==


<lang delphi>// The program name and the directory it was called from are in
<syntaxhighlight lang="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"
// param[0] , so given the axample of myprogram -c "alpha beta" -h "gamma"


Line 884: Line 884:
// param[3] = -h
// param[3] = -h
// param[4] = gamma
// param[4] = gamma
</syntaxhighlight>
</lang>


=={{header|Déjà Vu}}==
=={{header|Déjà Vu}}==
Command line arguments are found in <code>!args</code> and <code>!opts</code>.
Command line arguments are found in <code>!args</code> and <code>!opts</code>.


<lang dejavu>for i range 0 -- len !args:
<syntaxhighlight lang="dejavu">for i range 0 -- len !args:
print\( "Argument #" i " is " )
print\( "Argument #" i " is " )
. get-from !args i
. get-from !args i
Line 897: Line 897:


if has !opts :four:
if has !opts :four:
!. get-from !opts :four</lang>
!. get-from !opts :four</syntaxhighlight>
{{out}}
{{out}}
<pre>$ vu args-3.deja one two -c three --four=five
<pre>$ vu args-3.deja one two -c three --four=five
Line 917: Line 917:
This is however a limitation of the CP/M operating system, and not of Draco.
This is however a limitation of the CP/M operating system, and not of Draco.


<lang draco>\util.g
<syntaxhighlight lang="draco">\util.g


proc nonrec main() void:
proc nonrec main() void:
Line 927: Line 927:
writeln(i:3, ": '", par, "'")
writeln(i:3, ": '", par, "'")
od
od
corp</lang>
corp</syntaxhighlight>


{{out}}
{{out}}
Line 940: Line 940:
=={{header|E}}==
=={{header|E}}==


<lang e>interp.getArgs()</lang>
<syntaxhighlight lang="e">interp.getArgs()</syntaxhighlight>


=={{header|Eiffel}}==
=={{header|Eiffel}}==
Line 946: Line 946:
This class inherits functionality for dealing with command line arguments from class <code lang="eiffel">ARGUMENTS</code>. It uses the feature <code lang="eiffel">separate_character_option_value</code> to return the values by option name for each of the two arguments.
This class inherits functionality for dealing with command line arguments from class <code lang="eiffel">ARGUMENTS</code>. It uses the feature <code lang="eiffel">separate_character_option_value</code> to return the values by option name for each of the two arguments.


<lang eiffel >class
<syntaxhighlight lang="eiffel ">class
APPLICATION
APPLICATION
inherit
inherit
Line 962: Line 962:
io.read_line -- Keep console window open
io.read_line -- Keep console window open
end
end
end</lang>
end</syntaxhighlight>


Output (for command line arguments: -c "alpha beta" -h "gamma"):
Output (for command line arguments: -c "alpha beta" -h "gamma"):
Line 972: Line 972:
=={{header|Elena}}==
=={{header|Elena}}==
ELENA 4.x :
ELENA 4.x :
<lang elena>import system'routines;
<syntaxhighlight lang="elena">import system'routines;
import extensions;
import extensions;
Line 979: Line 979:
program_arguments.forEvery:(int i)
program_arguments.forEvery:(int i)
{ console.printLine("Argument ",i," is ",program_arguments[i]) }
{ console.printLine("Argument ",i," is ",program_arguments[i]) }
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 991: Line 991:
=={{header|Elixir}}==
=={{header|Elixir}}==
Elixir provides command line arguments via the <tt>System.argv()</tt> function.
Elixir provides command line arguments via the <tt>System.argv()</tt> function.
<lang elixir>#!/usr/bin/env elixir
<syntaxhighlight lang="elixir">#!/usr/bin/env elixir
IO.puts 'Arguments:'
IO.puts 'Arguments:'
Enum.map(System.argv(),&IO.puts(&1))</lang>
Enum.map(System.argv(),&IO.puts(&1))</syntaxhighlight>
Example run:
Example run:
<lang bash>$ ./show-args.exs a b=2 --3 -4
<syntaxhighlight lang="bash">$ ./show-args.exs a b=2 --3 -4
Arguments:
Arguments:
a
a
b=2
b=2
--3
--3
-4</lang>
-4</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==


<lang lisp>(while argv
<syntaxhighlight lang="lisp">(while argv
(message "Argument: %S" (pop argv)))</lang>
(message "Argument: %S" (pop argv)))</syntaxhighlight>


Invoke script:
Invoke script:
Line 1,013: Line 1,013:
=={{header|Erlang}}==
=={{header|Erlang}}==
When used as a script language the arguments is a list to the main/1 function. When compiled use init:get_arguments/0
When used as a script language the arguments is a list to the main/1 function. When compiled use init:get_arguments/0
<lang erlang>3> init:get_arguments().</lang>
<syntaxhighlight lang="erlang">3> init:get_arguments().</syntaxhighlight>
result
result
<lang erlang>[{root,["/usr/erlang/erl5.5"]},
<syntaxhighlight lang="erlang">[{root,["/usr/erlang/erl5.5"]},
{progname,["erl"]},
{progname,["erl"]},
{home,["/home/me"]},
{home,["/home/me"]},
{c,["alpha beta"]},
{c,["alpha beta"]},
{h,["gamma"]}]</lang>
{h,["gamma"]}]</syntaxhighlight>


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


<lang erlang>4> init:get_argument(h).
<syntaxhighlight lang="erlang">4> init:get_argument(h).
{ok,[["gamma"]]}
{ok,[["gamma"]]}
5> init:get_argument(c).
5> init:get_argument(c).
{ok,[["alpha beta"]]}</lang>
{ok,[["alpha beta"]]}</syntaxhighlight>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang Euphoria>constant cmd = command_line()
<syntaxhighlight lang="euphoria">constant cmd = command_line()
printf(1,"Interpreter/executable name: %s\n",{cmd[1]})
printf(1,"Interpreter/executable name: %s\n",{cmd[1]})
printf(1,"Program file name: %s\n",{cmd[2]})
printf(1,"Program file name: %s\n",{cmd[2]})
Line 1,037: Line 1,037:
printf(1,"#%d : %s\n",{i,cmd[i]})
printf(1,"#%d : %s\n",{i,cmd[i]})
end for
end for
end if</lang>
end if</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|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.
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.
<lang fsharp>#light
<syntaxhighlight lang="fsharp">#light
[<EntryPoint>]
[<EntryPoint>]
let main args =
let main args =
Array.iter (fun x -> printfn "%s" x) args
Array.iter (fun x -> printfn "%s" x) args
0</lang>
0</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
Line 1,052: Line 1,052:


=={{header|Fancy}}==
=={{header|Fancy}}==
<lang fancy>ARGV each: |a| {
<syntaxhighlight lang="fancy">ARGV each: |a| {
a println # print each given command line argument
a println # print each given command line argument
}</lang>
}</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==


<lang fantom>
<syntaxhighlight lang="fantom">
class Main
class Main
{
{
Line 1,066: Line 1,066:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Forth}}==
=={{header|Forth}}==
Line 1,072: Line 1,072:


{{works with|gforth|0.6.2}}
{{works with|gforth|0.6.2}}
<lang forth>\ args.f: print each command line argument on a separate line
<syntaxhighlight lang="forth">\ args.f: print each command line argument on a separate line
: main
: main
argc @ 0 do i arg type cr loop ;
argc @ 0 do i arg type cr loop ;


main bye</lang>
main bye</syntaxhighlight>


Here is output from a sample run.
Here is output from a sample run.
<lang forth>$ gforth args.f alpha "beta gamma" delta
<syntaxhighlight lang="forth">$ gforth args.f alpha "beta gamma" delta
gforth
gforth
args.f
args.f
Line 1,085: Line 1,085:
beta gamma
beta gamma
delta
delta
$</lang>
$</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|2003 and later}}
{{works with|Fortran|2003 and later}}
<lang fortran>program command_line_arguments
<syntaxhighlight lang="fortran">program command_line_arguments


implicit none
implicit none
Line 1,105: Line 1,105:


end program command_line_arguments
end program command_line_arguments
</syntaxhighlight>
</lang>
Note: This sample uses the Fortran 2003 intrinsic routines <code>command_argument_count</code> and <code>get_command_argument</code> instead of the nonstandard extensions <code>iargc</code> and <code>getarg</code>. Most Fortran compilers support both.
Note: This sample uses the Fortran 2003 intrinsic routines <code>command_argument_count</code> and <code>get_command_argument</code> instead of the nonstandard extensions <code>iargc</code> and <code>getarg</code>. Most Fortran compilers support both.


Sample usage:
Sample usage:
<lang>> ./a.out -c "alpha beta" -h "gamma"
<syntaxhighlight lang="text">> ./a.out -c "alpha beta" -h "gamma"
./a.out
./a.out
-c
-c
alpha beta
alpha beta
-h
-h
gamma</lang>
gamma</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


' Program (myprogram.exe) invoke as follows:
' Program (myprogram.exe) invoke as follows:
Line 1,125: Line 1,125:
Print
Print
Print "Press any key to quit"
Print "Press any key to quit"
Sleep</lang>
Sleep</syntaxhighlight>


{{out}}
{{out}}
Line 1,133: Line 1,133:


=={{header|Free Pascal}}==
=={{header|Free Pascal}}==
<lang pascal>
<syntaxhighlight lang="pascal">
Program listArguments(input, output, stdErr);
Program listArguments(input, output, stdErr);


Line 1,145: Line 1,145:
End;
End;
End.
End.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,158: Line 1,158:
=={{header|Frink}}==
=={{header|Frink}}==
Arguments to a program are available in the <CODE>ARGS</CODE> array variable.
Arguments to a program are available in the <CODE>ARGS</CODE> array variable.
<lang frink>
<syntaxhighlight lang="frink">
println[ARGS]
println[ARGS]
</syntaxhighlight>
</lang>


=={{header|FunL}}==
=={{header|FunL}}==
<lang funl>println( args )</lang>
<syntaxhighlight lang="funl">println( args )</syntaxhighlight>


=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=a1374aa441520314ad0c7decb1e91c97 Click this link to run this code]'''
'''[https://gambas-playground.proko.eu/?gist=a1374aa441520314ad0c7decb1e91c97 Click this link to run this code]'''
<lang gambas>PUBLIC SUB main()
<syntaxhighlight lang="gambas">PUBLIC SUB main()
DIM l AS Integer
DIM l AS Integer
DIM numparms AS Integer
DIM numparms AS Integer
Line 1,176: Line 1,176:
PRINT l; " : "; parm
PRINT l; " : "; parm
NEXT
NEXT
END</lang>
END</syntaxhighlight>


=={{header|Genie}}==
=={{header|Genie}}==
<lang genie>[indent=4]
<syntaxhighlight lang="genie">[indent=4]
/*
/*
Command line arguments, in Genie
Command line arguments, in Genie
Line 1,198: Line 1,198:
// to reiterate, args[0] is the command
// to reiterate, args[0] is the command
if args[0] is not null
if args[0] is not null
print "\nWith Genie, args[0] is the command: %s", args[0]</lang>
print "\nWith Genie, args[0] is the command: %s", args[0]</syntaxhighlight>


{{out}}
{{out}}
Line 1,217: Line 1,217:


This uses the <code>gsio</code> I/O operations, which are designed to be simple to implement on top of Haskell and simple to use. It also uses impmapM, which is a specific specialization of mapM for the HSGS implementation.
This uses the <code>gsio</code> I/O operations, which are designed to be simple to implement on top of Haskell and simple to use. It also uses impmapM, which is a specific specialization of mapM for the HSGS implementation.
<lang Global Script>λ 'as. impmapM (λ 'a. print qq{Argument: §(a)\n}) as</lang>
<syntaxhighlight lang="global script">λ 'as. impmapM (λ 'a. print qq{Argument: §(a)\n}) as</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
<syntaxhighlight lang="go">
<lang go>
package main
package main
import (
import (
Line 1,232: Line 1,232:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Groovy}}==
=={{header|Groovy}}==
Command-line arguments are accessible via the '''args''' list variable. The following is saved as the file "Echo.groovy":
Command-line arguments are accessible via the '''args''' list variable. The following is saved as the file "Echo.groovy":
<lang groovy>println args</lang>
<syntaxhighlight lang="groovy">println args</syntaxhighlight>


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:
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:
Line 1,249: Line 1,249:
=={{header|Harbour}}==
=={{header|Harbour}}==
Uses the Harbour-specific hb_PValue() function
Uses the Harbour-specific hb_PValue() function
<lang visualfoxpro>PROCEDURE Main()
<syntaxhighlight lang="visualfoxpro">PROCEDURE Main()


LOCAL i
LOCAL i
Line 1,257: Line 1,257:
NEXT
NEXT


RETURN</lang>
RETURN</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 1,264: Line 1,264:


myprog.hs:
myprog.hs:
<lang haskell>import System
<syntaxhighlight lang="haskell">import System
main = getArgs >>= print</lang>
main = getArgs >>= print</syntaxhighlight>
<pre>
<pre>
myprog a -h b c
myprog a -h b c
Line 1,272: Line 1,272:


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>DO i = 2, 100 ! 1 is HicEst.exe
<syntaxhighlight lang="hicest">DO i = 2, 100 ! 1 is HicEst.exe
EDIT(Text=$CMD_LINE, SePaRators='-"', ITeM=i, IF ' ', EXit, ENDIF, Parse=cmd, GetPosition=position)
EDIT(Text=$CMD_LINE, SePaRators='-"', ITeM=i, IF ' ', EXit, ENDIF, Parse=cmd, GetPosition=position)
IF(position > 0) WRITE(Messagebox) cmd
IF(position > 0) WRITE(Messagebox) cmd
ENDDO</lang>
ENDDO</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Command line parameters are passed to Icon/Unicon programs as a list of strings.
Command line parameters are passed to Icon/Unicon programs as a list of strings.
<lang Icon>procedure main(arglist)
<syntaxhighlight lang="icon">procedure main(arglist)
every write(!arglist)
every write(!arglist)
end</lang>
end</syntaxhighlight>


{{libheader|Icon Programming Library}} includes [http://www.cs.arizona.edu/icon/library/procs/options.htm options] that parses the command line as switches and arguments and returns the results in a table.
{{libheader|Icon Programming Library}} includes [http://www.cs.arizona.edu/icon/library/procs/options.htm options] that parses the command line as switches and arguments and returns the results in a table.


=={{header|Io}}==
=={{header|Io}}==
<lang io>System args foreach(a, a println)</lang>
<syntaxhighlight lang="io">System args foreach(a, a println)</syntaxhighlight>


=={{header|Ioke}}==
=={{header|Ioke}}==
<lang ioke>System programArguments each(println)</lang>
<syntaxhighlight lang="ioke">System programArguments each(println)</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
Line 1,295: Line 1,295:
The global <code>ARGV</code> holds the command line arguments. Thus, a program to display them:
The global <code>ARGV</code> holds the command line arguments. Thus, a program to display them:


<lang J> ARGV</lang>
<syntaxhighlight lang="j"> ARGV</syntaxhighlight>


In a non-interactive context, we would instead use <code>echo ARGV</code>.
In a non-interactive context, we would instead use <code>echo ARGV</code>.
Line 1,301: Line 1,301:
=={{header|Java}}==
=={{header|Java}}==


<lang java>public class Arguments {
<syntaxhighlight lang="java">public class Arguments {
public static void main(String[] args) {
public static void main(String[] args) {
System.out.println("There are " + args.length + " arguments given.");
System.out.println("There are " + args.length + " arguments given.");
Line 1,307: Line 1,307:
System.out.println("The argument #" + (i+1) + " is " + args[i] + " and is at index " + i);
System.out.println("The argument #" + (i+1) + " is " + args[i] + " and is at index " + i);
}
}
}</lang>
}</syntaxhighlight>


For more sophisticated command-line option and option-argument parsing use the [http://commons.apache.org/cli '''Apache Commons CLI'''] (command-line interface) library.
For more sophisticated command-line option and option-argument parsing use the [http://commons.apache.org/cli '''Apache Commons CLI'''] (command-line interface) library.
Line 1,313: Line 1,313:
=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{works with|Node.js}}
{{works with|Node.js}}
<lang javascript>process.argv.forEach((val, index) => {
<syntaxhighlight lang="javascript">process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`);
console.log(`${index}: ${val}`);
});</lang>
});</syntaxhighlight>
{{works with|JScript}}
{{works with|JScript}}
<lang javascript>var objArgs = WScript.Arguments;
<syntaxhighlight lang="javascript">var objArgs = WScript.Arguments;
for (var i = 0; i < objArgs.length; i++)
for (var i = 0; i < objArgs.length; i++)
WScript.Echo(objArgs.Item(i));</lang>
WScript.Echo(objArgs.Item(i));</syntaxhighlight>
{{works with|JScript.NET (compiled with jsc.exe)}}
{{works with|JScript.NET (compiled with jsc.exe)}}
<lang javascript>import System;
<syntaxhighlight lang="javascript">import System;
var argv:String[] = Environment.GetCommandLineArgs();
var argv:String[] = Environment.GetCommandLineArgs();
for (var i in argv)
for (var i in argv)
print(argv[i]);</lang>
print(argv[i]);</syntaxhighlight>
{{works with|Rhino}}
{{works with|Rhino}}
{{works with|SpiderMonkey}}
{{works with|SpiderMonkey}}
<lang javascript>for (var i = 0; i < arguments.length; i++)
<syntaxhighlight lang="javascript">for (var i = 0; i < arguments.length; i++)
print(arguments[i]);</lang>
print(arguments[i]);</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
Line 1,347: Line 1,347:
$ jq -n '$ARGS' --args a b
$ jq -n '$ARGS' --args a b


yields:<lang json>{
yields:<syntaxhighlight lang="json">{
"positional": [
"positional": [
"a",
"a",
Line 1,353: Line 1,353:
],
],
"named": {}
"named": {}
}</lang>
}</syntaxhighlight>


Arguments specified with ''--args'' are always read as JSON strings; arguments specified with ''--jsonargs''
Arguments specified with ''--args'' are always read as JSON strings; arguments specified with ''--jsonargs''
Line 1,372: Line 1,372:


=={{header|Jsish}}==
=={{header|Jsish}}==
<lang javascript>#!/usr/local/bin/jsish
<syntaxhighlight lang="javascript">#!/usr/local/bin/jsish
puts(Info.argv0());
puts(Info.argv0());
puts(console.args);</lang>
puts(console.args);</syntaxhighlight>


{{out}}
{{out}}
Line 1,383: Line 1,383:
=={{header|Julia}}==
=={{header|Julia}}==
Works when the Julia program is run as a file argument to julia.exe.
Works when the Julia program is run as a file argument to julia.exe.
<lang Julia>using Printf
<syntaxhighlight lang="julia">using Printf


prog = Base.basename(Base.source_path())
prog = Base.basename(Base.source_path())
Line 1,391: Line 1,391:
println(" ", s)
println(" ", s)
end
end
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,408: Line 1,408:
per line:
per line:


<syntaxhighlight lang="k">
<lang K>
.p'.a
.p'.a
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Java}}
{{trans|Java}}
<lang scala>fun main(args: Array<String>) {
<syntaxhighlight lang="scala">fun main(args: Array<String>) {
println("There are " + args.size + " arguments given.")
println("There are " + args.size + " arguments given.")
args.forEachIndexed { i, a -> println("The argument #${i+1} is $a and is at index $i") }
args.forEachIndexed { i, a -> println("The argument #${i+1} is $a and is at index $i") }
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
See Java output.
See Java output.


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang lasso>#!/usr/bin/lasso9
<syntaxhighlight lang="lasso">#!/usr/bin/lasso9


iterate($argv) => {
iterate($argv) => {
stdoutnl("Argument " + loop_count + ": " + loop_value)
stdoutnl("Argument " + loop_count + ": " + loop_value)
}</lang>
}</syntaxhighlight>
Output:
Output:
<lang shell>$ lasso9 arguments.lasso -c "alpha beta" -h "gamma"
<syntaxhighlight lang="shell">$ lasso9 arguments.lasso -c "alpha beta" -h "gamma"
Argument 1: arguments.lasso
Argument 1: arguments.lasso
Argument 2: -c
Argument 2: -c
Argument 3: alpha beta
Argument 3: alpha beta
Argument 4: -h
Argument 4: -h
Argument 5: gamma</lang>
Argument 5: gamma</syntaxhighlight>


=={{header|LFE}}==
=={{header|LFE}}==


To demonstrate this, we can start the LFE REPL up with the parameters for this example:
To demonstrate this, we can start the LFE REPL up with the parameters for this example:
<lang shell>
<syntaxhighlight lang="shell">
$ ./bin/lfe -pa ebin/ -c "alpha beta" -h "gamma"
$ ./bin/lfe -pa ebin/ -c "alpha beta" -h "gamma"
</syntaxhighlight>
</lang>


Once we're in the shell, we can get all the initializing arguments with this call:
Once we're in the shell, we can get all the initializing arguments with this call:
<lang lisp>
<syntaxhighlight lang="lisp">
> (: init get_arguments)
> (: init get_arguments)
(#(root ("/opt/erlang/r15b03"))
(#(root ("/opt/erlang/r15b03"))
Line 1,452: Line 1,452:
#(c ("alpha beta"))
#(c ("alpha beta"))
#(h ("gamma")))
#(h ("gamma")))
</syntaxhighlight>
</lang>


We can also get specific arguments if we know their keys:
We can also get specific arguments if we know their keys:
<lang lisp>
<syntaxhighlight lang="lisp">
> (: init get_argument 'c)
> (: init get_argument 'c)
#(ok (("alpha beta")))
#(ok (("alpha beta")))
> (: init get_argument 'h)
> (: init get_argument 'h)
#(ok (("gamma")))
#(ok (("gamma")))
</syntaxhighlight>
</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<lang lb>print CommandLine$</lang>
<syntaxhighlight lang="lb">print CommandLine$</syntaxhighlight>


=={{header|Lingo}}==
=={{header|Lingo}}==
<lang lingo>put the commandline
<syntaxhighlight lang="lingo">put the commandline
-- "-c alpha beta -h gamma"</lang>
-- "-c alpha beta -h gamma"</syntaxhighlight>


In latest versions of Mac OS X, the above approach doesn't work anymore. But there is a free "Xtra" (binary plugin/shared library) called "CommandLine Xtra" that works both in Windows and Mac OS X and returns the command-line parsed into a lingo list (array):
In latest versions of Mac OS X, the above approach doesn't work anymore. But there is a free "Xtra" (binary plugin/shared library) called "CommandLine Xtra" that works both in Windows and Mac OS X and returns the command-line parsed into a lingo list (array):


{{libheader|CommandLine Xtra}}
{{libheader|CommandLine Xtra}}
<lang lingo>put getCommandLineArgs()
<syntaxhighlight lang="lingo">put getCommandLineArgs()
-- ["-c", "alpha beta", "-h", "gamma"]</lang>
-- ["-c", "alpha beta", "-h", "gamma"]</syntaxhighlight>


=={{header|Logo}}==
=={{header|Logo}}==
Line 1,480: Line 1,480:
logo file.logo - arg1 arg2 arg3
logo file.logo - arg1 arg2 arg3
Then the arguments after the "-" are found in a list in variable :COMMAND.LINE
Then the arguments after the "-" are found in a list in variable :COMMAND.LINE
<lang logo>show :COMMAND.LINE
<syntaxhighlight lang="logo">show :COMMAND.LINE
[arg1 arg2 arg3]</lang>
[arg1 arg2 arg3]</syntaxhighlight>
Alternatively, make the first line of an executable logo script:
Alternatively, make the first line of an executable logo script:
#! /usr/bin/logo -
#! /usr/bin/logo -
Line 1,488: Line 1,488:


=={{header|LSE64}}==
=={{header|LSE64}}==
<lang lse64>argc , nl # number of arguments (including command itself)
<syntaxhighlight lang="lse64">argc , nl # number of arguments (including command itself)
0 # argument
0 # argument
dup arg dup 0 = || ,t 1 + repeat
dup arg dup 0 = || ,t 1 + repeat
drop</lang>
drop</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Line 1,497: Line 1,497:
The lua scripting language does not use argc and argv conventions for the command line parameters. Instead, the command line parameters to the main script are provided through the global table arg. The script name is placed into element zero of arg, and the script parameters go into the subsequent elements:
The lua scripting language does not use argc and argv conventions for the command line parameters. Instead, the command line parameters to the main script are provided through the global table arg. The script name is placed into element zero of arg, and the script parameters go into the subsequent elements:


<lang lua>print( "Program name:", arg[0] )
<syntaxhighlight lang="lua">print( "Program name:", arg[0] )


print "Arguments:"
print "Arguments:"
for i = 1, #arg do
for i = 1, #arg do
print( i," ", arg[i] )
print( i," ", arg[i] )
end</lang>
end</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 1,511: Line 1,511:
For this example we make a script, save to temporary directory, and call it passing arguments. We can use Win as shell substitute in M2000 environment, or the Use statement. Reading the shell statement Win we can see how the command line composed. We call the m2000.exe in the appdir$ (application directory, is the path to M2000.exe), and pass a string as a file with a path. That path will be the current path for the new start of m2000.exe the host for M2000 Interpreter (an activeX dll).
For this example we make a script, save to temporary directory, and call it passing arguments. We can use Win as shell substitute in M2000 environment, or the Use statement. Reading the shell statement Win we can see how the command line composed. We call the m2000.exe in the appdir$ (application directory, is the path to M2000.exe), and pass a string as a file with a path. That path will be the current path for the new start of m2000.exe the host for M2000 Interpreter (an activeX dll).


<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
Module Checkit {
Document a$ = {
Document a$ = {
Line 1,538: Line 1,538:
}
}
Checkit
Checkit
</syntaxhighlight>
</lang>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
myprogram:
myprogram:
<lang Mathematica>#!/usr/local/bin/MathematicaScript -script
<syntaxhighlight lang="mathematica">#!/usr/local/bin/MathematicaScript -script
$CommandLine</lang>
$CommandLine</syntaxhighlight>
Output:
Output:
<pre>{myprogram,-c,alpha beta,-h,gamma}</pre>
<pre>{myprogram,-c,alpha beta,-h,gamma}</pre>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang>
<syntaxhighlight lang="text">
:- module cmd_line_args.
:- module cmd_line_args.
:- interface.
:- interface.
Line 1,568: Line 1,568:
print_arg(Arg, ArgNum, ArgNum + 1, !IO) :-
print_arg(Arg, ArgNum, ArgNum + 1, !IO) :-
io.format("the argument #%d is %s\n", [i(ArgNum), s(Arg)], !IO).
io.format("the argument #%d is %s\n", [i(ArgNum), s(Arg)], !IO).
</syntaxhighlight>
</lang>


=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
<lang min>args</lang>
<syntaxhighlight lang="min">args</syntaxhighlight>


=={{header|MMIX}}==
=={{header|MMIX}}==
<lang mmix>argv IS $1
<syntaxhighlight lang="mmix">argv IS $1
argc IS $0
argc IS $0
i IS $2
i IS $2
Line 1,597: Line 1,597:
TRAP 0,Halt,0
TRAP 0,Halt,0


NewLine BYTE #a,0</lang>
NewLine BYTE #a,0</syntaxhighlight>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE try;
<syntaxhighlight lang="modula2">MODULE try;


FROM Arguments IMPORT GetArgs, ArgTable, GetEnv;
FROM Arguments IMPORT GetArgs, ArgTable, GetEnv;
Line 1,619: Line 1,619:
INC (item)
INC (item)
UNTIL item = count
UNTIL item = count
END try.</lang>
END try.</syntaxhighlight>
Example:
Example:
<syntaxhighlight lang="modula-2">
<lang Modula-2>
jan@Beryllium:~/modula/test$ try jantje zag eens pruimen hangen
jan@Beryllium:~/modula/test$ try jantje zag eens pruimen hangen
Count = 6
Count = 6
Line 1,630: Line 1,630:
4 : pruimen
4 : pruimen
5 : hangen
5 : hangen
</syntaxhighlight>
</lang>


=={{header|Modula-3}}==
=={{header|Modula-3}}==
Command line parameters are accessed using the <tt>Params</tt> module.
Command line parameters are accessed using the <tt>Params</tt> module.
<lang modula3>MODULE Args EXPORTS Main;
<syntaxhighlight lang="modula3">MODULE Args EXPORTS Main;


IMPORT IO, Params;
IMPORT IO, Params;
Line 1,645: Line 1,645:
END;
END;
END;
END;
END Args.</lang>
END Args.</syntaxhighlight>


Output:
Output:
Line 1,662: Line 1,662:
=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
{{trans|Ursa}}
{{trans|Ursa}}
<syntaxhighlight lang="nanoquery">//
<lang Nanoquery>//
// command-line arguments
// command-line arguments
//
//
Line 1,669: Line 1,669:
for i in range(0, len(args) - 1)
for i in range(0, len(args) - 1)
println args[i]
println args[i]
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>$ java -jar ../nanoquery-2.3_1700.jar -b cmdline.nq "alpha beta" -h "gamma"
<pre>$ java -jar ../nanoquery-2.3_1700.jar -b cmdline.nq "alpha beta" -h "gamma"
Line 1,679: Line 1,679:


=={{header|Neko}}==
=={{header|Neko}}==
<lang actionscript>/* command line arguments, neko */
<syntaxhighlight lang="actionscript">/* command line arguments, neko */
var argc = $asize($loader.args)
var argc = $asize($loader.args)


Line 1,686: Line 1,686:


var arg = 0
var arg = 0
while arg < argc $print($loader.args[arg ++= 1], "\n")</lang>
while arg < argc $print($loader.args[arg ++= 1], "\n")</syntaxhighlight>


{{out}}
{{out}}
Line 1,698: Line 1,698:


=={{header|Nemerle}}==
=={{header|Nemerle}}==
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;


Line 1,711: Line 1,711:
foreach (cl_arg in cl_args) Write($"$cl_arg ");
foreach (cl_arg in cl_args) Write($"$cl_arg ");
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
In a stand-alone application NetRexx places the command string passed to it in a variable called <tt>arg</tt>.
In a stand-alone application NetRexx places the command string passed to it in a variable called <tt>arg</tt>.
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
-- sample arguments: -c "alpha beta" -h "gamma"
-- sample arguments: -c "alpha beta" -h "gamma"
say "program arguments:" arg
say "program arguments:" arg
</syntaxhighlight>
</lang>
'''Output:'''
'''Output:'''
<pre>
<pre>
Line 1,725: Line 1,725:


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import os
<syntaxhighlight lang="nim">import os
echo "program name: ", getAppFilename()
echo "program name: ", getAppFilename()
echo "Arguments:"
echo "Arguments:"
for arg in commandLineParams():
for arg in commandLineParams():
echo arg</lang>
echo arg</syntaxhighlight>


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
{{works with|oo2c}}
{{works with|oo2c}}
<lang oberon2>
<syntaxhighlight lang="oberon2">
MODULE CommandLineArguments;
MODULE CommandLineArguments;
IMPORT
IMPORT
Line 1,747: Line 1,747:
Out.String("4.-: ");Out.String(Args.AsString(4));Out.Ln
Out.String("4.-: ");Out.String(Args.AsString(4));Out.Ln
END CommandLineArguments.
END CommandLineArguments.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,759: Line 1,759:


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>
<syntaxhighlight lang="objeck">
class Line {
class Line {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
Line 1,767: Line 1,767:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Objective-C}}==
=={{header|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:
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:
<lang objc>NSArray *args = [[NSProcessInfo processInfo] arguments];
<syntaxhighlight lang="objc">NSArray *args = [[NSProcessInfo processInfo] arguments];
NSLog(@"This program is named %@.", [args objectAtIndex:0]);
NSLog(@"This program is named %@.", [args objectAtIndex:0]);
NSLog(@"There are %d arguments.", [args count] - 1);
NSLog(@"There are %d arguments.", [args count] - 1);
for (i = 1; i < [args count]; ++i){
for (i = 1; i < [args count]; ++i){
NSLog(@"the argument #%d is %@", i, [args objectAtIndex:i]);
NSLog(@"the argument #%d is %@", i, [args objectAtIndex:i]);
}</lang>
}</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 1,783: Line 1,783:
The program name is also passed as "argument", so the array length is actually one more than the number of program arguments.
The program name is also passed as "argument", so the array length is actually one more than the number of program arguments.


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


=== Using the [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Arg.html Arg] module ===
=== Using the [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Arg.html Arg] module ===


<lang ocaml>(* default values *)
<syntaxhighlight lang="ocaml">(* default values *)
let somebool = ref false
let somebool = ref false
let somestr = ref ""
let somestr = ref ""
Line 1,812: Line 1,812:


Printf.printf " %b %d '%s'\n" !somebool !someint !somestr;
Printf.printf " %b %d '%s'\n" !somebool !someint !somestr;
;;</lang>
;;</syntaxhighlight>




Line 1,835: Line 1,835:
The first argument is the program name, so this list is never empty.
The first argument is the program name, so this list is never empty.


<lang Oforth>System.Args println</lang>
<syntaxhighlight lang="oforth">System.Args println</syntaxhighlight>


=={{header|Oz}}==
=={{header|Oz}}==
===Raw arguments===
===Raw arguments===
Like in C, but without the program name:
Like in C, but without the program name:
<lang oz>functor
<syntaxhighlight lang="oz">functor
import Application System
import Application System
define
define
Line 1,846: Line 1,846:
{ForAll ArgList System.showInfo}
{ForAll ArgList System.showInfo}
{Application.exit 0}
{Application.exit 0}
end</lang>
end</syntaxhighlight>


===Preprocessed arguments===
===Preprocessed arguments===
<lang oz>functor
<syntaxhighlight lang="oz">functor
import Application System
import Application System
define
define
Line 1,865: Line 1,865:
{System.showInfo Args.h}
{System.showInfo Args.h}
{Application.exit 0}
{Application.exit 0}
end</lang>
end</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,874: Line 1,874:
@ARGV is the array containing all command line parameters
@ARGV is the array containing all command line parameters


<lang perl>my @params = @ARGV;
<syntaxhighlight lang="perl">my @params = @ARGV;
my $params_size = @ARGV;
my $params_size = @ARGV;
my $second = $ARGV[1];
my $second = $ARGV[1];
my $fifth = $ARGV[4];</lang>
my $fifth = $ARGV[4];</syntaxhighlight>


If you don't mind importing a module:
If you don't mind importing a module:


<lang perl>use Getopt::Long;
<syntaxhighlight lang="perl">use Getopt::Long;
GetOptions (
GetOptions (
'help|h' => \my $help,
'help|h' => \my $help,
'verbose|v' => \my $verbose,
'verbose|v' => \my $verbose,
);</lang>
);</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cmd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">command_line</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cmd</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">command_line</span><span style="color: #0000FF;">()</span>
Line 1,903: Line 1,903:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
When interpreting, the first two elements returned by command_line() are {interpreter,source}.<br>
When interpreting, the first two elements returned by command_line() are {interpreter,source}.<br>
When compiled, the first two elements are instead {executable,executable}, so the parameters (if any) are consistently the 3rd element onwards.
When compiled, the first two elements are instead {executable,executable}, so the parameters (if any) are consistently the 3rd element onwards.
Line 1,944: Line 1,944:
When PHP is run from the command line, the special variables <tt>$argv</tt> and <tt>$argc</tt> contain the array of arguments, and the number of arguments, respectively. The program name is passed as the first argument.
When PHP is run from the command line, the special variables <tt>$argv</tt> and <tt>$argc</tt> contain the array of arguments, and the number of arguments, respectively. The program name is passed as the first argument.


<lang php><?php
<syntaxhighlight lang="php"><?php
$program_name = $argv[0];
$program_name = $argv[0];
$second_arg = $argv[2];
$second_arg = $argv[2];
$all_args_without_program_name = array_shift($argv);
$all_args_without_program_name = array_shift($argv);
</syntaxhighlight>
</lang>


=={{header|Picat}}==
=={{header|Picat}}==
Picat has no built-in option parser, and the user must write a specific parser for each use case. The arguments to a Picat programs are available via <code>main/1</code> as a list of strings.
Picat has no built-in option parser, and the user must write a specific parser for each use case. The arguments to a Picat programs are available via <code>main/1</code> as a list of strings.


<lang Picat>main(ARGS) =>
<syntaxhighlight lang="picat">main(ARGS) =>
println(ARGS).
println(ARGS).
main(_) => true.</lang>
main(_) => true.</syntaxhighlight>


{{out}}
{{out}}
Line 1,978: Line 1,978:
and then '[http://software-lab.de/doc/refL.html#load load]' all remaining
and then '[http://software-lab.de/doc/refL.html#load load]' all remaining
command line arguments.
command line arguments.
<lang PicoLisp>#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
<syntaxhighlight lang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l


(de c ()
(de c ()
Line 1,987: Line 1,987:


(load T)
(load T)
(bye)</lang>
(bye)</syntaxhighlight>
Output:
Output:
<pre>$ ./myprogram -c "alpha beta" -h "gamma"
<pre>$ ./myprogram -c "alpha beta" -h "gamma"
Line 1,994: Line 1,994:


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>
<syntaxhighlight lang="pli">
/* The entire command line except the command word itself is passed */
/* The entire command line except the command word itself is passed */
/* to the parameter variable in PL/I. */
/* to the parameter variable in PL/I. */
Line 2,003: Line 2,003:


end program;
end program;
</syntaxhighlight>
</lang>


=={{header|Pop11}}==
=={{header|Pop11}}==
Line 2,009: Line 2,009:
variable poparglist contains list of command line arguments (as strings). One can use iteration over list to process then (for example print).
variable poparglist contains list of command line arguments (as strings). One can use iteration over list to process then (for example print).


<lang pop11>lvars arg;
<syntaxhighlight lang="pop11">lvars arg;
for arg in poparglist do
for arg in poparglist do
printf(arg, '->%s<-\n');
printf(arg, '->%s<-\n');
endfor;</lang>
endfor;</syntaxhighlight>


=={{header|PowerBASIC}}==
=={{header|PowerBASIC}}==
For versions of PowerBASIC prior to [[PB/Win]] 9 and [[PB/CC]] 5, the only option available is identical to the one used by [[#BASIC|QuickBASIC]] above:
For versions of PowerBASIC prior to [[PB/Win]] 9 and [[PB/CC]] 5, the only option available is identical to the one used by [[#BASIC|QuickBASIC]] above:
<lang powerbasic>? "args: '"; COMMAND$; "'"</lang>
<syntaxhighlight lang="powerbasic">? "args: '"; COMMAND$; "'"</syntaxhighlight>


Current versions of PowerBASIC (with the likely exception of [[PB/DOS]]) include <code>COMMAND$()</code> that works similarly to [[FreeBASIC]]'s <code>COMMAND$()</code>, except that you can't retrieve the application's name:
Current versions of PowerBASIC (with the likely exception of [[PB/DOS]]) include <code>COMMAND$()</code> that works similarly to [[FreeBASIC]]'s <code>COMMAND$()</code>, except that you can't retrieve the application's name:
<lang powerbasic>'these two both return ALL args
<syntaxhighlight lang="powerbasic">'these two both return ALL args
? COMMAND$
? COMMAND$
? COMMAND$(0)
? COMMAND$(0)
Line 2,026: Line 2,026:
PRINT "The argument "; i; " is "; COMMAND$(i)
PRINT "The argument "; i; " is "; COMMAND$(i)
i = i + 1
i = i + 1
LOOP</lang>
LOOP</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
In PowerShell the arguments to a script can be accessed with the <code>$args</code> array:
In PowerShell the arguments to a script can be accessed with the <code>$args</code> array:
<lang powershell>$i = 0
<syntaxhighlight lang="powershell">$i = 0
foreach ($s in $args) {
foreach ($s in $args) {
Write-Host Argument (++$i) is $s
Write-Host Argument (++$i) is $s
}</lang>
}</syntaxhighlight>


=={{header|Pure}}==
=={{header|Pure}}==
Arguments are in global variables, argc and argv.
Arguments are in global variables, argc and argv.


<lang pure>
<syntaxhighlight lang="pure">
using system;
using system;


printf "There are %d command line argumants\n" argc;
printf "There are %d command line argumants\n" argc;
puts "They are " $$ map (puts) argv;
puts "They are " $$ map (puts) argv;
</syntaxhighlight>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
Line 2,049: Line 2,049:
===Reading all parameters===
===Reading all parameters===
You can easily read all parameters by using ProgramParameter() without argument.
You can easily read all parameters by using ProgramParameter() without argument.
<lang PureBasic>If OpenConsole()
<syntaxhighlight lang="purebasic">If OpenConsole()
Define n=CountProgramParameters()
Define n=CountProgramParameters()
PrintN("Reading all parameters")
PrintN("Reading all parameters")
Line 2,059: Line 2,059:
Input()
Input()
CloseConsole()
CloseConsole()
EndIf</lang>
EndIf</syntaxhighlight>
===Reading specific parameters===
===Reading specific parameters===
You can specify which parameter 'n' to read.
You can specify which parameter 'n' to read.
<lang PureBasic>If OpenConsole()
<syntaxhighlight lang="purebasic">If OpenConsole()
Define n
Define n
PrintN("Reading specific pameters")
PrintN("Reading specific pameters")
Line 2,071: Line 2,071:
Input()
Input()
CloseConsole()
CloseConsole()
EndIf</lang>
EndIf</syntaxhighlight>


=={{header|Python}}==
=={{header|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:
''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:


<lang python>import sys
<syntaxhighlight lang="python">import sys
program_name = sys.argv[0]
program_name = sys.argv[0]
arguments = sys.argv[1:]
arguments = sys.argv[1:]
count = len(arguments)</lang>
count = len(arguments)</syntaxhighlight>


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).
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).
Line 2,091: Line 2,091:
Suppose you want to call your script <tt>test.r</tt> with the arguments <tt>a=1 b=c(2,5,6)</tt>, where <tt>b</tt> is a numeric vector. Suppose you also want to redirect your output to <tt>test.out</tt> (not that you have a choice--I still don't know how to make R send shell-script output to stdout). You would then run
Suppose you want to call your script <tt>test.r</tt> with the arguments <tt>a=1 b=c(2,5,6)</tt>, where <tt>b</tt> is a numeric vector. Suppose you also want to redirect your output to <tt>test.out</tt> (not that you have a choice--I still don't know how to make R send shell-script output to stdout). You would then run


<lang R>R CMD BATCH --vanilla --slave '--args a=1 b=c(2,5,6)' test.r test.out</lang>
<syntaxhighlight lang="r">R CMD BATCH --vanilla --slave '--args a=1 b=c(2,5,6)' test.r test.out</syntaxhighlight>


from the commandline, with the following text in <tt>test.r</tt>:
from the commandline, with the following text in <tt>test.r</tt>:


<lang R># Read the commandline arguments
<syntaxhighlight lang="r"># Read the commandline arguments
args <- (commandArgs(TRUE))
args <- (commandArgs(TRUE))


Line 2,112: Line 2,112:
}
}
print(a*2)
print(a*2)
print(b*3)</lang>
print(b*3)</syntaxhighlight>


(possibly preceding code that actually does something :-) Your output <tt>test.out</tt> would then contain (e.g., if you <tt>cat</tt> it)
(possibly preceding code that actually does something :-) Your output <tt>test.out</tt> would then contain (e.g., if you <tt>cat</tt> it)
Line 2,134: Line 2,134:
The following is the simplest program that prints the command-line arguments:
The following is the simplest program that prints the command-line arguments:


<lang scheme>#lang racket
<syntaxhighlight lang="scheme">#lang racket
(current-command-line-arguments)</lang>
(current-command-line-arguments)</syntaxhighlight>


You can also explicitly print each argument to standard output:
You can also explicitly print each argument to standard output:


<lang scheme>#lang racket
<syntaxhighlight lang="scheme">#lang racket


(for ([arg (current-command-line-arguments)]) (displayln arg))</lang>
(for ([arg (current-command-line-arguments)]) (displayln arg))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 2,147: Line 2,147:
Perl 5's <code>@ARGV</code> is available as <code>@*ARGS</code>. Alternatively, if you define a subroutine named <code>MAIN</code>, Perl will automatically process <code>@*ARGS</code> according to Unix conventions and <code>MAIN</code>'s signature (or signatures, if your <code>MAIN</code> is a multi sub) and then call <code>MAIN</code> with appropriate arguments; for more detailed information see: https://docs.raku.org/language/create-cli
Perl 5's <code>@ARGV</code> is available as <code>@*ARGS</code>. Alternatively, if you define a subroutine named <code>MAIN</code>, Perl will automatically process <code>@*ARGS</code> according to Unix conventions and <code>MAIN</code>'s signature (or signatures, if your <code>MAIN</code> is a multi sub) and then call <code>MAIN</code> with appropriate arguments; for more detailed information see: https://docs.raku.org/language/create-cli


<lang perl6># with arguments supplied
<syntaxhighlight lang="raku" line># with arguments supplied
$ raku -e 'sub MAIN($x, $y) { say $x + $y }' 3 5
$ raku -e 'sub MAIN($x, $y) { say $x + $y }' 3 5
8
8
Line 2,154: Line 2,154:
$ raku -e 'sub MAIN($x, $y) { say $x + $y }' 3
$ raku -e 'sub MAIN($x, $y) { say $x + $y }' 3
Usage:
Usage:
-e '...' x y</lang>
-e '...' x y</syntaxhighlight>


If the program is stored in a file, the file name is printed instead of <code>-e '...'</code>.
If the program is stored in a file, the file name is printed instead of <code>-e '...'</code>.


=={{header|RapidQ}}==
=={{header|RapidQ}}==
<lang rapidq>PRINT "This program is named "; Command$(0)
<syntaxhighlight lang="rapidq">PRINT "This program is named "; Command$(0)
FOR i=1 TO CommandCount
FOR i=1 TO CommandCount
PRINT "The argument "; i; " is "; Command$(i)
PRINT "The argument "; i; " is "; Command$(i)
NEXT i</lang>
NEXT i</syntaxhighlight>


=={{header|Raven}}==
=={{header|Raven}}==


<lang raven>ARGS print
<syntaxhighlight lang="raven">ARGS print


stack (6 items)
stack (6 items)
Line 2,174: Line 2,174:
3 => "alpha beta"
3 => "alpha beta"
4 => "-h"
4 => "-h"
5 => "gamma"</lang>
5 => "gamma"</syntaxhighlight>


=={{header|REALbasic}}==
=={{header|REALbasic}}==
<lang vb>Function Run(args() as String) As Integer
<syntaxhighlight lang="vb">Function Run(args() as String) As Integer
For each arg As String In args
For each arg As String In args
Stdout.WriteLine(arg)
Stdout.WriteLine(arg)
Next
Next
End Function</lang>
End Function</syntaxhighlight>
Output (given arguments: ''--foo !bar "bat bang"''):
Output (given arguments: ''--foo !bar "bat bang"''):
appName.exe
appName.exe
Line 2,190: Line 2,190:
=={{header|REXX}}==
=={{header|REXX}}==
The entire command line arguments (as a single string) are passed by REXX to the program.
The entire command line arguments (as a single string) are passed by REXX to the program.
<lang rexx>say 'command arguments:'
<syntaxhighlight lang="rexx">say 'command arguments:'
say arg(1)</lang>
say arg(1)</syntaxhighlight>
Input:
Input:


Line 2,199: Line 2,199:
only options that start with a minus (-) are to be examined
only options that start with a minus (-) are to be examined
and assumed to be options.
and assumed to be options.
<lang rexx>parse arg aaa /*get the arguments. */
<syntaxhighlight lang="rexx">parse arg aaa /*get the arguments. */
/*another version: */
/*another version: */
/* aaa=arg(1) */
/* aaa=arg(1) */
Line 2,220: Line 2,220:
say
say
say 'options='opts
say 'options='opts
say ' data='data</lang>
say ' data='data</syntaxhighlight>


;Note to users of Microsoft Windows and Regina REXX:
;Note to users of Microsoft Windows and Regina REXX:
Line 2,283: Line 2,283:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
see copy("=",30) + nl
see copy("=",30) + nl
see "Command Line Parameters" + nl
see "Command Line Parameters" + nl
Line 2,292: Line 2,292:
see x + nl
see x + nl
next
next
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
Line 2,298: Line 2,298:


myprog:
myprog:
<lang ruby>#! /usr/bin/env ruby
<syntaxhighlight lang="ruby">#! /usr/bin/env ruby
p ARGV</lang>
p ARGV</syntaxhighlight>


myprog a -h b c
myprog a -h b c
Line 2,305: Line 2,305:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>use std::env;
<syntaxhighlight lang="rust">use std::env;


fn main(){
fn main(){
let args: Vec<_> = env::args().collect();
let args: Vec<_> = env::args().collect();
println!("{:?}", args);
println!("{:?}", args);
}</lang>
}</syntaxhighlight>
Run:
Run:
<lang>./program -c "alpha beta" -h "gamma"
<syntaxhighlight lang="text">./program -c "alpha beta" -h "gamma"
["./program", "-c", "alpha beta", "-h", "gamma"]</lang>
["./program", "-c", "alpha beta", "-h", "gamma"]</syntaxhighlight>


=={{header|S-lang}}==
=={{header|S-lang}}==
The command-line arguments exist in the array __argv:
The command-line arguments exist in the array __argv:
<lang S-lang>variable a;
<syntaxhighlight lang="s-lang">variable a;
foreach a (__argv)
foreach a (__argv)
print(a);
print(a);
</lang>Note 1: This array can be changed by calling
</syntaxhighlight>Note 1: This array can be changed by calling


__set_argc_argv(new_argv);
__set_argc_argv(new_argv);
Line 2,336: Line 2,336:


=={{header|Sather}}==
=={{header|Sather}}==
<lang sather>class MAIN is
<syntaxhighlight lang="sather">class MAIN is
main(args:ARRAY{STR}) is
main(args:ARRAY{STR}) is
loop
loop
Line 2,342: Line 2,342:
end;
end;
end;
end;
end;</lang>
end;</syntaxhighlight>


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.
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.
Line 2,361: Line 2,361:
array of strings, and returns unit. That array contains the command line arguments.
array of strings, and returns unit. That array contains the command line arguments.


<lang scala>object CommandLineArguments extends App {
<syntaxhighlight lang="scala">object CommandLineArguments extends App {
println(s"Received the following arguments: + ${args.mkString("", ", ", ".")}")
println(s"Received the following arguments: + ${args.mkString("", ", ", ".")}")
}</lang>
}</syntaxhighlight>


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


<lang scala>println(s"Received the following arguments: + ${argv.mkString("", ", ", ".")}")</lang>
<syntaxhighlight lang="scala">println(s"Received the following arguments: + ${argv.mkString("", ", ", ".")}")</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==


<lang scheme> (define (main args)
<syntaxhighlight lang="scheme"> (define (main args)
(for-each (lambda (arg) (display arg) (newline)) args))</lang>
(for-each (lambda (arg) (display arg) (newline)) args))</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==


<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 2,386: Line 2,386:
writeln("The argument #" <& i <& " is " <& argv(PROGRAM)[i]);
writeln("The argument #" <& i <& " is " <& argv(PROGRAM)[i]);
end for;
end for;
end func;</lang>
end func;</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
Command line arguments are available in the ARGV array.
Command line arguments are available in the ARGV array.
<lang ruby>say ARGV;</lang>
<syntaxhighlight lang="ruby">say ARGV;</syntaxhighlight>
{{out}}
{{out}}
<pre>% myprog -c "alpha beta" -h "gamma"
<pre>% myprog -c "alpha beta" -h "gamma"
Line 2,397: Line 2,397:


=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>StartupArguments do: [| :arg | inform: arg]</lang>
<syntaxhighlight lang="slate">StartupArguments do: [| :arg | inform: arg]</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
{{works with|GNU Smalltalk}}
<lang smalltalk>(1 to: Smalltalk getArgc) do: [ :i |
<syntaxhighlight lang="smalltalk">(1 to: Smalltalk getArgc) do: [ :i |
(Smalltalk getArgv: i) displayNl
(Smalltalk getArgv: i) displayNl
]</lang>
]</syntaxhighlight>


{{works with|Smalltalk/X}}
{{works with|Smalltalk/X}}
<lang smalltalk>Smalltalk commandLineArguments printCR.
<syntaxhighlight lang="smalltalk">Smalltalk commandLineArguments printCR.
Smalltalk commandLineArguments do:[:each | each printCR]</lang>
Smalltalk commandLineArguments do:[:each | each printCR]</syntaxhighlight>


=={{header|Standard ML}}==
=={{header|Standard ML}}==


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


=={{header|Swift}}==
=={{header|Swift}}==


<lang swift>let args = Process.arguments
<syntaxhighlight lang="swift">let args = Process.arguments
println("This program is named \(args[0]).")
println("This program is named \(args[0]).")
println("There are \(args.count-1) arguments.")
println("There are \(args.count-1) arguments.")
for i in 1..<args.count {
for i in 1..<args.count {
println("the argument #\(i) is \(args[i])")
println("the argument #\(i) is \(args[i])")
}</lang>
}</syntaxhighlight>


Alternately:
Alternately:


{{works with|Swift|1.2+}}
{{works with|Swift|1.2+}}
<lang swift>println("This program is named \(String.fromCString(Process.unsafeArgv[0])!).")
<syntaxhighlight lang="swift">println("This program is named \(String.fromCString(Process.unsafeArgv[0])!).")
println("There are \(Process.argc-1) arguments.")
println("There are \(Process.argc-1) arguments.")
for i in 1 ..< Int(Process.argc) {
for i in 1 ..< Int(Process.argc) {
println("the argument #\(i) is \(String.fromCString(Process.unsafeArgv[i])!)")
println("the argument #\(i) is \(String.fromCString(Process.unsafeArgv[i])!)")
}</lang>
}</syntaxhighlight>
{{works with|Swift|1.0-1.1}}
{{works with|Swift|1.0-1.1}}
<lang swift>println("This program is named \(String.fromCString(C_ARGV[0])!).")
<syntaxhighlight lang="swift">println("This program is named \(String.fromCString(C_ARGV[0])!).")
println("There are \(C_ARGC-1) arguments.")
println("There are \(C_ARGC-1) arguments.")
for i in 1 ..< Int(C_ARGC) {
for i in 1 ..< Int(C_ARGC) {
println("the argument #\(i) is \(String.fromCString(C_ARGV[i])!)")
println("the argument #\(i) is \(String.fromCString(C_ARGV[i])!)")
}</lang>
}</syntaxhighlight>


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<lang tailspin>
<syntaxhighlight lang="tailspin">
$ARGS -> !OUT::write
$ARGS -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,454: Line 2,454:
The predefined global variable <tt>argc</tt> contains the number of arguments passed to the program after the script being executed, <tt>argv</tt> contains those arguments as a list. (The name of the script is in the <tt>argv0</tt> global variable, and the name of the executable interpreter itself is returned by the command <code>info nameofexecutable</code>.) Retrieving the second argument might look something like this:
The predefined global variable <tt>argc</tt> contains the number of arguments passed to the program after the script being executed, <tt>argv</tt> contains those arguments as a list. (The name of the script is in the <tt>argv0</tt> global variable, and the name of the executable interpreter itself is returned by the command <code>info nameofexecutable</code>.) Retrieving the second argument might look something like this:


<lang tcl>if { $argc > 1 } {
<syntaxhighlight lang="tcl">if { $argc > 1 } {
puts [lindex $argv 1]
puts [lindex $argv 1]
}</lang>
}</syntaxhighlight>


(Tcl counts from zero, thus <tt>[lindex $list 1]</tt> retrieves the second item in the list)
(Tcl counts from zero, thus <tt>[lindex $list 1]</tt> retrieves the second item in the list)
Line 2,466: Line 2,466:
number of arguments is provided by #args.
number of arguments is provided by #args.


<lang toka>[ arglist array.get type cr ] is show-arg
<syntaxhighlight lang="toka">[ arglist array.get type cr ] is show-arg
[ dup . char: = emit space ] is #=
[ dup . char: = emit space ] is #=
1 #args [ i #= show-arg ] countedLoop</lang>
1 #args [ i #= show-arg ] countedLoop</syntaxhighlight>


=={{header|TXR}}==
=={{header|TXR}}==
Line 2,476: Line 2,476:
This <code>@(next :args)</code> should be written as the first line of the TXR program, because TXR otherwise interprets the first argument as the name of an input file to open.
This <code>@(next :args)</code> should be written as the first line of the TXR program, because TXR otherwise interprets the first argument as the name of an input file to open.


<lang txr>@(next :args)
<syntaxhighlight lang="txr">@(next :args)
@(collect)
@(collect)
@arg
@arg
Line 2,482: Line 2,482:
@(output)
@(output)
My args are: {@(rep)@arg, @(last)@arg@(end)}
My args are: {@(rep)@arg, @(last)@arg@(end)}
@(end)</lang>
@(end)</syntaxhighlight>


<pre>$ ./txr args.txr
<pre>$ ./txr args.txr
Line 2,495: Line 2,495:
Here is an example program which requires exactly three arguments. Note how <code>ldiff</code> is used to compute the arguments that are processed by TXR (the interpreter name, any special arguments and script name), to print an accurate usage message.
Here is an example program which requires exactly three arguments. Note how <code>ldiff</code> is used to compute the arguments that are processed by TXR (the interpreter name, any special arguments and script name), to print an accurate usage message.


<lang txrlisp>(tree-case *args*
<syntaxhighlight lang="txrlisp">(tree-case *args*
((a b c) (put-line "got three args, thanks!"))
((a b c) (put-line "got three args, thanks!"))
(else (put-line `usage: @(ldiff *full-args* *args*) <arg1> <arg2> <arg3>`)))</lang>
(else (put-line `usage: @(ldiff *full-args* *args*) <arg1> <arg2> <arg3>`)))</syntaxhighlight>
{{out}}
{{out}}
<pre>$ txr command-line-args.txr 1 2
<pre>$ txr command-line-args.txr 1 2
Line 2,509: Line 2,509:
===[[Bourne Shell]]===
===[[Bourne Shell]]===
To retrieve the entire list of arguments:
To retrieve the entire list of arguments:
<lang bash>WHOLELIST="$@"</lang>
<syntaxhighlight lang="bash">WHOLELIST="$@"</syntaxhighlight>
To retrieve the second and fifth arguments:
To retrieve the second and fifth arguments:
<lang bash>SECOND=$2
<syntaxhighlight lang="bash">SECOND=$2
FIFTH=$5</lang>
FIFTH=$5</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
In Ursa, all command line arguments (including the program name as invoked) are contained in the string stream args.
In Ursa, all command line arguments (including the program name as invoked) are contained in the string stream args.
<lang ursa>#
<syntaxhighlight lang="ursa">#
# command-line arguments
# command-line arguments
#
#
Line 2,523: Line 2,523:
for (decl int i) (< i (size args)) (inc i)
for (decl int i) (< i (size args)) (inc i)
out args<i> endl console
out args<i> endl console
end for</lang>
end for</syntaxhighlight>


Sample shell session in the Bourne shell:
Sample shell session in the Bourne shell:
Line 2,538: Line 2,538:
This example application does nothing but display the data
This example application does nothing but display the data
structure on standard output.
structure on standard output.
<lang Ursala>#import std
<syntaxhighlight lang="ursala">#import std


#executable ('parameterized','')
#executable ('parameterized','')


clarg = <.file$[contents: --<''>+ _option%LP]>+ ~command.options</lang>
clarg = <.file$[contents: --<''>+ _option%LP]>+ ~command.options</syntaxhighlight>
Here is a bash terminal session.
Here is a bash terminal session.
<pre>$ clarg -c alpha,beta -h gamma --foo=bar,baz
<pre>$ clarg -c alpha,beta -h gamma --foo=bar,baz
Line 2,563: Line 2,563:


args.v
args.v
<lang v>$stack puts
<syntaxhighlight lang="v">$stack puts


./args.v a b c
./args.v a b c
=[args.v a b c]</lang>
=[args.v a b c]</syntaxhighlight>


=={{header|vbScript}}==
=={{header|vbScript}}==


<lang vbscript>
<syntaxhighlight lang="vbscript">
'Command line arguments can be accessed all together by
'Command line arguments can be accessed all together by


Line 2,588: Line 2,588:
Wscript.Echo "arg=", arg
Wscript.Echo "arg=", arg
Next
Next
</syntaxhighlight>
</lang>


=={{header|Visual Basic}}==
=={{header|Visual Basic}}==


Like [[#BASIC|Qbasic]], Visual Basic returns all of the args in the built-in variable <code>Command$</code>:
Like [[#BASIC|Qbasic]], Visual Basic returns all of the args in the built-in variable <code>Command$</code>:
<lang vb>Sub Main
<syntaxhighlight lang="vb">Sub Main
MsgBox Command$
MsgBox Command$
End Sub</lang>
End Sub</syntaxhighlight>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Line 2,601: Line 2,601:
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.
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.


<lang vbnet>Sub Main(ByVal args As String())
<syntaxhighlight lang="vbnet">Sub Main(ByVal args As String())
For Each token In args
For Each token In args
Console.WriteLine(token)
Console.WriteLine(token)
Next
Next
End Sub</lang>
End Sub</syntaxhighlight>


=={{header|Vlang}}==
=={{header|Vlang}}==
This assumes that the following script, myscript.v, is run as follows:
This assumes that the following script, myscript.v, is run as follows:
$ v run myscript.v -c "alpha beta" -h "gamma"
$ v run myscript.v -c "alpha beta" -h "gamma"
<lang vlang>import os
<syntaxhighlight lang="vlang">import os
fn main() {
fn main() {
Line 2,616: Line 2,616:
println("the argument #$i is $x")
println("the argument #$i is $x")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,629: Line 2,629:
This assumes that the following script, myscript.wren, is run as follows:
This assumes that the following script, myscript.wren, is run as follows:
$ wren myscript.wren -c "alpha beta" -h "gamma"
$ wren myscript.wren -c "alpha beta" -h "gamma"
<lang ecmascript>import "os" for Process
<syntaxhighlight lang="ecmascript">import "os" for Process


System.print(Process.arguments)</lang>
System.print(Process.arguments)</syntaxhighlight>


{{out}}
{{out}}
Line 2,641: Line 2,641:
Characters following the program name are copied into a buffer that is accessible as device 8.
Characters following the program name are copied into a buffer that is accessible as device 8.
This displays the example command line with quote marks stripped off.
This displays the example command line with quote marks stripped off.
<lang XPL0>int C;
<syntaxhighlight lang="xpl0">int C;
[loop [C:= ChIn(8);
[loop [C:= ChIn(8);
if C = \EOF\$1A then quit;
if C = \EOF\$1A then quit;
Line 2,647: Line 2,647:
];
];
CrLf(0);
CrLf(0);
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 2,656: Line 2,656:
=={{header|zkl}}==
=={{header|zkl}}==
File myprogram.zkl:
File myprogram.zkl:
<lang zkl>System.argv.println();
<syntaxhighlight lang="zkl">System.argv.println();
vm.arglist.println();</lang>
vm.arglist.println();</syntaxhighlight>
zkl myprogram -c "alpha beta" -h "gamma"
zkl myprogram -c "alpha beta" -h "gamma"
{{out}}
{{out}}