How do I get the command line arguments in Go without the "flags" package?
Nevermind.
package main
import (
"fmt"
"os"
)
func main() {
args := os.Args
fmt.Printf("%d\n", len(args))
for i := 0; i<len(args); i++ {
fmt.Printf("%s\n", args[i])
}
}
The documentation is quite incomplete, though.
The first argument of os.Args is the name of the go file, so to get only the command line arguments, you should do something like this
package main
import (
"fmt"
"os"
)
func main() {
args := os.Args[1:]
for i := 0; i<len(args); i++ {
fmt.Println(args[i])
}
}