WEBVTT 0 00:01.640 --> 00:04.160 Welcome back! In the previous lecture, 1 00:04.220 --> 00:09.760 you have learned about the Args variable In this lecture, I'm going a code in the coding editor. 2 00:09.910 --> 00:10.960 Let's get started. 3 00:18.910 --> 00:22.960 Now first let me show you what the os.Args variable contains. 4 00:22.960 --> 00:30.200 I'm going to call Printf with os.Args. This will print the values inside the Args slice. 5 00:30.200 --> 00:32.910 By the way, I'll explain how the Printf function works later on. 6 00:33.950 --> 00:35.530 Let's run it now. 7 00:37.700 --> 00:44.270 Here, it prints the Args slice with one string value inside. As you can see, Printf prints the type 8 00:44.270 --> 00:48.280 of the slice here. and its values here. 9 00:48.400 --> 00:54.170 If I were using the Println function, then it would only print the values. However, with Printf, 10 00:54.280 --> 00:57.070 I can also get the type of a variable or value. 11 00:57.280 --> 01:02.430 Anyway. As I told you, this one is the first parameter of the Args slice. 12 01:02.470 --> 01:09.960 So this is the path to the running program. But it's a temporary path. So it doesn't exist anymore. 13 01:09.970 --> 01:13.390 It's because the "go run" tool creates temporary executable files. 14 01:13.480 --> 01:17.070 However, "go build" (command) creates an executable file permanently. 15 01:17.530 --> 01:24.220 So to make the program name more meaningful, I'm going to use the "go build" tool instead. 16 01:24.310 --> 01:29.910 Let's build this program using the go build tool this time. This argument -o 17 01:29.970 --> 01:33.630 allows me to give a name to the compiled program. 18 01:33.930 --> 01:41.040 I'm going to name it greeter. As you can see, the greeter program is here. 19 01:41.220 --> 01:47.830 "go build" has compiled my program, and created an executable program named greeter. 20 01:47.900 --> 01:48.870 Let's run it now. 21 01:49.780 --> 01:53.050 I think this looks better. As you can see, 22 01:53.050 --> 01:57.400 now the first value of the Args slice is greeter (the name of the program). 23 01:57.470 --> 02:02.480 Let me run it with a few example arguments. 24 02:02.530 --> 02:10.220 Here's the first argument, and the second one, and the last one. As you can see, Go has loaded up all the 25 02:10.220 --> 02:16.280 arguments into the Args slice automatically. The first value is still the path to the executing program. 26 02:17.210 --> 02:20.620 And, the rest are the arguments that I've passed to the program. 27 02:21.200 --> 02:26.450 And I can get each one of them. Let's do it. 28 02:26.450 --> 02:28.280 Now, I'm going to the first argument of the Args slice. 29 02:33.910 --> 02:34.810 and the second one. 30 02:41.980 --> 02:42.880 and it the third one. 31 02:48.020 --> 02:52.690 and the last one. 32 02:52.750 --> 02:54.900 Now, I'm going to show you the len function. 33 03:05.810 --> 03:10.100 This len function here can find how many items inside a slice value. 34 03:11.360 --> 03:18.350 Let's build it one more time, and let's run it now. Here it prints each item one by one. 35 03:18.350 --> 03:22.280 These are the exact same values inside of the Args strings slice, right? 36 03:24.890 --> 03:27.670 os.Args with an index value of zero here gets the path. 37 03:27.680 --> 03:34.240 And the index value of one here gets the first argument. 38 03:35.730 --> 03:41.310 Two gets the second argument. And, three gets the third argument. Cool. 39 03:43.830 --> 03:50.970 As you can see, it prints four since there are really four items inside the slice. However, note that there are 40 03:50.970 --> 03:55.790 only three arguments, not four. But the path value as its first value, 41 03:55.860 --> 03:58.820 the slice's length becomes four. 42 03:58.980 --> 03:59.650 Alright. 43 03:59.750 --> 04:05.130 That's all for now. In the next lecture, I'm going to create the actual greeter program finally. See you there.