Command-line arguments: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 99:
end run
</lang>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
Line 197 ⟶ 198:
}
}</lang>
 
 
=={{header|Babel}}==
Line 396:
(void) printf("the argument #%d is %s\n", i, argv[i]);
return EXIT_SUCCESS;
}</lang>
 
=={{header|C++}}==
Command line arguments are passed the same way as in C.
 
This example uses iostream. Traditional C I/O also works.
 
<lang cpp>#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;
}</lang>
 
Line 439 ⟶ 422:
}
}
}</lang>
 
=={{header|C++}}==
Command line arguments are passed the same way as in C.
 
This example uses iostream. Traditional C I/O also works.
 
<lang cpp>#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;
}</lang>
 
Line 613:
the value of P7 is
the value of P8 is</pre>
 
=={{header|Delphi}}==
 
<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"
 
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
// param[1] = -c
// param[2] = alpha beta
// param[3] = -h
// param[4] = gamma
</lang>
 
=={{header|Déjà Vu}}==
Line 636 ⟶ 653:
 
The order of command line ''options'' is lost.
 
=={{header|Delphi}}==
 
<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"
 
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
// param[1] = -c
// param[2] = alpha beta
// param[3] = -h
// param[4] = gamma
</lang>
 
=={{header|E}}==
Line 759:
Array.iter (fun x -> printfn "%s" x) args
0</lang>
 
=={{header|Factor}}==
USING: io sequences command-line ;
Line 798 ⟶ 799:
delta
$</lang>
 
=={{header|Fortran}}==
{{works with|Fortran|2003 and later}}
Line 1,177 ⟶ 1,179:
dup arg dup 0 = || ,t 1 + repeat
drop</lang>
 
=={{header|Lua}}==
 
Line 1,187 ⟶ 1,190:
print( i," ", arg[i] )
end</lang>
 
=={{header|M2000 Interpreter}}==
function quote$("a") return "a" a string in ""
Line 1,222 ⟶ 1,226:
Checkit
</lang>
 
 
=={{header|Mathematica}}==
Line 1,511 ⟶ 1,514:
% ocaml arg.ml
false 0 <nowiki>''</nowiki>
 
 
=={{header|Oforth}}==
Line 1,571 ⟶ 1,573:
'verbose|v' => \my $verbose,
);</lang>
 
=={{header|Perl 6}}==
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; see [http://perlcabal.org/syn/S06.html#Declaring_a_MAIN_subroutine Synopsis 6] or [http://perlgeek.de/en/article/5-to-6#post_14|5-to-6].
 
<lang perl6># with arguments supplied
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3 5
8
 
# missing argument:
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3
Usage:
-e '...' x y</lang>
 
If the program is stored in a file, the file name is printed instead of <code>-e '...'</code>.
 
=={{header|Phix}}==
Line 1,819 ⟶ 1,807:
 
(for ([arg (current-command-line-arguments)]) (displayln arg))</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
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; see [http://perlcabal.org/syn/S06.html#Declaring_a_MAIN_subroutine Synopsis 6] or [http://perlgeek.de/en/article/5-to-6#post_14|5-to-6].
 
<lang perl6># with arguments supplied
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3 5
8
 
# missing argument:
$ perl6 -e 'sub MAIN($x, $y) { say $x + $y }' 3
Usage:
-e '...' x y</lang>
 
If the program is stored in a file, the file name is printed instead of <code>-e '...'</code>.
 
=={{header|RapidQ}}==
Line 2,228 ⟶ 2,231:
./args.v a b c
=[args.v a b c]</lang>
 
=={{header|Visual Basic}}==
 
Like [[#BASIC|Qbasic]], Visual Basic returns all of the args in the built-in variable <code>Command$</code>:
<lang vb>Sub Main
MsgBox Command$
End Sub</lang>
 
=={{header|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.
 
<lang vbnet>Sub Main(ByVal args As String())
For Each token In args
Console.WriteLine(token)
Next
End Sub</lang>
 
 
=={{header|vbScript}}==
Line 2,268 ⟶ 2,253:
Next
</lang>
 
=={{header|Visual Basic}}==
 
Like [[#BASIC|Qbasic]], Visual Basic returns all of the args in the built-in variable <code>Command$</code>:
<lang vb>Sub Main
MsgBox Command$
End Sub</lang>
 
=={{header|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.
 
<lang vbnet>Sub Main(ByVal args As String())
For Each token In args
Console.WriteLine(token)
Next
End Sub</lang>
 
=={{header|zkl}}==