gobyexample/044-command-line-arguments/command-line-arguments.go
Mark McGranaghan 6750b72724 updates
2012-09-23 12:47:27 -07:00

27 lines
690 B
Go

// ## Command Line Arguments
// Use `os.Args` to access command-line arguments and
// the name of the program.
package main
import "os"
import "fmt"
func main() {
// `os.Args` includes the program name as the first
// value.
argsWithProg := os.Args
argsWithoutProg := os.Args[1:]
// `Args` are a slice, you can get individual args
// with normal indexing.
arg := os.Args[3]
fmt.Println(argsWithProg)
fmt.Println(argsWithoutProg)
fmt.Println(arg)
}
// todo: discuss building before here