《go程序设计语言》

package main

import (
    "flag"
    "fmt"
    "strings"
)

var n = flag.Bool("n", false, "omit trailing newline") //注册一个bool类型flag n,默认值为false,返回保存值为false的指针
var sep = flag.String("s", " ", "separator")           //注册一个string类型flag s,默认值为空,返回保存值为空的指针

func main() {
    flag.Parse()                               //解析命令行参数,写入注册的flag里
    fmt.Print(strings.Join(flag.Args(), *sep)) //flag.Args()获取参数
    if !*n {
        fmt.Println()
    }
}
╰ go run main.go a bc def                                          -╯
a bc def
╰ go run main.go -s / a bc def                                     -╯
a/bc/def
╰ go run main.go -s a bc def                                       -╯
bcadef
╰ go run main.go -n a bc def                                       -╯
a bc def%
╰ go run main.go -help                                             -╯
Usage of /var/folders/vp/xk96hm1s28s4yggxg0hpxrb00000gn/T/go-build378451942/b001/exe/main:
  -n    omit trailing newline
  -s string
        separator (default " ")