command-line-arguments

Command-Line Arguments

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
package main

import (
	"fmt"
	"os"
)

func main() {
	argsWithProg := os.Args
	argsWithoutProg := os.Args[1:]

	arg := os.Args[3]

	fmt.Printf("%#v,%T\n", argsWithProg, argsWithProg)
	fmt.Printf("%v,%T\n", argsWithoutProg, argsWithoutProg)
	fmt.Printf("%v,%T\n", arg, arg)
}
1
2
3
4
PS D:\Dev\Go\byExample\command_line_arguments> .\main.exe a b c d
[]string{"D:\\Dev\\Go\\byExample\\command_line_arguments\\main.exe", "a", "b", "c", "d"},[]string
[a b c d],[]string
c,string
最后修改 October 10, 2024: 更新 (a4b8f85)