-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguements01.go
36 lines (25 loc) · 1004 Bytes
/
arguements01.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Alta3 Research | RZFeeser
Reading positional arguments from the command line*/
package main
import (
"fmt"
"os"
)
func main() {
// os.Args provides access to raw CLI arguments
argsWithProg := os.Args // includes program name
argsWithoutProg := os.Args[1:] // does not include program name
arg := os.Args[3] // select the 3rd argument
// remember: the 1st argument is the name
// of the program
last_arg := os.Args[len(os.Args)-1] // select the last argument // select the last argument
// display the results
fmt.Println("All arguments, including the program name:")
fmt.Println(argsWithProg)
fmt.Println("All arguments, (without the program name:")
fmt.Println(argsWithoutProg)
// select "just" the 3rd argument
fmt.Println(arg)
// display the last argument
fmt.Println(last_arg)
}