{{fbdoc item="title" value="COMMAND"}}----
Returns command line parameters used to call the program

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Command** ( [[KeyPgByval|byval]] //index// [[KeyPgAs|as]] [[KeyPgLong|long]] = -1 ) [[KeyPgAs|as]] [[KeyPgString|string]]
##
{{fbdoc item="usage"}}##
	//result// = **Command**[$]( [ //index// ] )
##
{{fbdoc item="param"}}
	##//index//##
		Zero-based index for a particular command-line argument.

{{fbdoc item="ret"}}
	  Returns the command-line arguments(s).

{{fbdoc item="desc"}}
	##**Command**## returns command-line arguments passed to the program upon execution.
	
	If ##//index//## is less than zero (##< 0##), a space-separated list of all command-line arguments is returned, otherwise, a single argument is returned. A value of zero (##0##) returns the name of the executable; and values of one (##1##) and greater return each command-line argument.
	
	If ##//index//## is greater than the number of arguments passed to the program, the null string (##"####"##) is returned.
	
	When the command line is parsed for arguments, everything between double quotes in the parameter list will be considered as a single block, and is returned without the double quotes.
	
	By default, filename globbing for arguments (expansion of wildcards to filenames) is used on all ports of ""FreeBASIC"" for compatibility.  Arguments on the command line containing wildcards are typically not expanded if when no file is matched or if properly quoted.  Other special characters for redirection are typically not returned unless properly quoted.  Consult the documentation on the shell being used for more information on the proper quoting of command line arguments.
	
~&//**WARNING**: By nature of constructor precedence in ""FreeBASIC"" and main() initialization, calling ##**Command**## within a global constructor (module constructor or UDT constructor called for static/shared object) is not safe (may even induce a runtime error).//
	
	__Disabling filename globbing under Win32__
		Define the following global variable(s) somewhere in the source:
		{{fbdoc item="filename" value="examples/manual/check/KeyPgCommand_mingw.bas"}}%%(freebasic)
'' For MinGW.org and Cygwin runtimes:
Extern _CRT_glob Alias "_CRT_glob" As Long
Dim Shared _CRT_glob As Long = 0

'' For MinGW-w64 runtime:
Extern _dowildcard Alias "_dowildcard" As Long
Dim Shared _dowildcard As Long = 0
%%
	
	__Disabling filename globbing under Dos__
		Define the following function somewhere in the source:
		{{fbdoc item="filename" value="examples/manual/check/KeyPgCommand_Dos.bas"}}%%(freebasic)
Function __crt0_glob_function Alias "__crt0_glob_function" ( ByVal arg As UByte Ptr ) As UByte Ptr Ptr
  Return 0
End Function
%%

	__Disabling filename globbing under Linux__
		Filename globbing is handled by the command shell.  Quote the argument containing wildcards or disable filename globbing in the shell prior to executing the command.  For example in bash use 'set -f' to disable wildcard expansion

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/system/command.bas"}}%%(freebasic)
print "program launched via: " & command(0)

dim as integer i = 1
do
	dim as string arg = command(i)
	if len(arg) = 0 then
		exit do
	end if

	print "command line argument " & i & " = """ & arg & """"
	i += 1
loop

if i = 1 then
	print "(no command line arguments)"
end if

sleep
%%

{{fbdoc item="lang"}}
	- The string type suffix "$" is obligatory in the //[[CompilerOptlang|-lang qb]]// dialect.
	- The string type suffix "$" is optional in the //[[CompilerOptlang|-lang fblite]]// dialect.
	- The string type suffix "$" is forbidden in the //[[CompilerOptlang|-lang fb]]// dialect.

{{fbdoc item="diff"}}
	- The numeric argument was not supported in QB.
	- QB converted the parameter list to uppercase before returning it, ""FreeBASIC"" doesn't.
	- By default arguments containing wildcard characters are expanded (filename globbing)

{{fbdoc item="see"}}
	- ##[[KeyPgDdfbargc|__FB_ARGC__]]##
	- ##[[KeyPgDdfbargv|__FB_ARGV__]]##
	- ##[[KeyPgExec|Exec]]##
	- ##[[KeyPgRun|Run]]##

{{fbdoc item="back" value="CatPgOpsys|Operating System Functions"}}
