Next: Finding Duplicate Lines, Previous: The First Echo Command using a for
Loop, Up: Tutorial [Index]
Example 1.1: Modify the
echo
program to also printos.Args[0]
, the name of the command that invoked it.
// Exercise 1.1 prints the command name and the command-line arguments package main import("fmt";"os";"strings") func main() { fmt.Println(strings.Join(os.Args[0:], " ")) }
Example 1.2: Modify the
echo
program to print the index and value of each of its arguments, one per line.
// Exercise 1.2 prints each of the command-line arguments with an index, one per line package main import("fmt";"os") func main() { for index, value := range os.Args[0:] { fmt.Println(index, value) } }
Example 1.3: Experiment to measure the difference in running time between our potentially inefficient versions and the one that uses
strings.Join
. (Section 1.6 illustrates part of thetime
package, and Section 11.4 shows how to write benchmark tests for systematic performance evaluation.)