首页 > 技术文章 > command-line arguments _ golang

jackkiexu 2015-03-31 13:22 原文

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 (
    "fmt"
    "os"
)

func main() {

    argsWithProg := os.Args
    argsWithoutProg := os.Args[1:]

    arg := os.Args[3]

    fmt.Println(argsWithProg)
    fmt.Println(argsWithoutProg)
    fmt.Println(arg)
}
[./commonLineArgument a b c d]
[a b c d]
c

总结 : 

  1 : ....

推荐阅读