September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will present a Go version of the cat(1) command-line utility. If you give one or more command-line arguments to cat(1), then cat(1) will print their contents on the screen. However, if you just type cat(1) on your Unix shell, then cat(1) will wait for your input, which will be terminated when you type Ctrl + D.
The name of the Go implementation will be cat.go and will be presented in three parts.
The first part of cat.go is the following:
package main import ( "bufio" "fmt" "io" "os" )
The second part is the following:
func catFile(filename string) error { f, err := os.Open(filename) if err != nil { return err } defer f.Close() scanner := bufio.NewScanner(f) for scanner.Scan() { fmt.Println(scanner.Text()) ...Read now
Unlock full access