lean into examples

This commit is contained in:
Mark McGranaghan
2012-10-09 21:02:12 -07:00
parent 5d1775bdaa
commit 8daa226a48
130 changed files with 4 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
// Use `os.Args` to access command-line arguments and
// the name of the program.
package main
import "os"
import "fmt"
func main() {
// `os.Args` includes the program name as the first
// value.
argsWithProg := os.Args
argsWithoutProg := os.Args[1:]
// `Args` are a slice, you can get individual args
// with normal indexing.
arg := os.Args[3]
fmt.Println(argsWithProg)
fmt.Println(argsWithoutProg)
fmt.Println(arg)
}
// todo: discuss building before here

View File

@@ -0,0 +1,9 @@
# Build a `command-line-args` binary so that we have
# the expected program name.
$ go build command-line-arguments
$ ./command-line-arguments a b c d
[command-line-arguments a b c d]
[a b c d]
c