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) string

Parameters & Attributes

NameTypeDescription
iintZero-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))}
Go Reference