Standard library / flag
flag.Arg()
Returns the indexed positional argument; missing indexes return an empty string. Run with arguments: ["file"]. Expected stdout: '"file" ""\n'.
Formal Syntax & Structure
go syntaxgo
func Arg(i int) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based index among remaining positional arguments. |
Return Value
string
Returns the indexed positional argument; missing indexes return an empty string.
Working Example
Example Snippetgo
package main
import ( "flag" "fmt")
func main() { v := flag.Int("x", 0, "value") _ = v flag.Parse() fmt.Printf("%q %q\n", flag.Arg(0), flag.Arg(2))}