Go语言基础-2.命令行参数

1.vim osArg.go

package main

import (
        "fmt"
        "os"
)

func main() {
        fmt.Println(os.Args)
        fmt.Println(os.Args[0])
        fmt.Println(os.Args[1],os.Args[2])
}

输出

$go run osArgs.go a b
[/var/folders/51/zw99trqs1fvc2qxct_7s0hrw0000gp/T/go-build828352928/b001/exe/osArgs a b]
/var/folders/51/zw99trqs1fvc2qxct_7s0hrw0000gp/T/go-build828352928/b001/exe/osArgs
a b
a b

你可能感兴趣的:(Go语言基础-2.命令行参数)