Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (26 sloc) 1003 Bytes
/*
Title: 59.Command_Line_Arguments.go
Author: OpenSource
Date: 2017-05-23
Description: For Study
Command-line arguments are a common way to parameterize execution of programs.
For example, go run hello.go uses run and hello.go arguments to the go program.
*/
package main
import "os"
import "fmt"
func main(){
fmt.Println("59.Command_Line_Arguments.go---------Start------------\n\n")
// os.Args provides access to raw command-line arguments.
// Note that the first value in this slice is the path to the program,
// and os.Args[1:] holds the arguments to the program.
argsWithProg := os.Args
argsWithoutProg := os.Args[1:]
// You can get individual args with normal indexing.
arg := os.Args[3]
fmt.Println(argsWithProg)
fmt.Println(argsWithoutProg)
fmt.Println(arg)
// To experiment with command-line arguments it’s best to build a binary with go build first.
fmt.Println("\n\n59.Command_Line_Arguments.go-----------End------------")
}
You can’t perform that action at this time.