September 2017
Intermediate to advanced
466 pages
9h 33m
English
Apart from using command-line arguments to get user input, which is the preferred approach in systems programming, there exist ways to ask the user for input.
Two such examples are the rm(1) and mv(1) commands when used with the -i option:
$ touch aFile $ rm -i aFile remove aFile? y $ touch aFile $ touch ../aFile $ mv -i ../aFile . overwrite ./aFile? (y/n [n]) y
So, this section will show you how to mimic the previous behavior in your Go code by making your program understand the -i parameter without actually implementing the functionality of either rm(1) or mv(1).
The simplest function for getting user input is called fmt.Scanln() and reads an entire line. Other functions for getting user input include fmt.Scan(), fmt.Scanf() ...
Read now
Unlock full access