###### print-hello-arg.go
```go
package main
import (
"fmt"
"os")
func main() {
if len(os.Args) == 1 {
fmt.Println("Error: missing name")
os.Exit(1)
}
fmt.Println("Hello", os.Args[1])
}
```
```
# Without arguments
$ go run print-hello-arg.go
Error: missing name
exit status 1
# With arguments
$ go run print-hello-arg.go Foo
Hello Foo
```
This program extends the previous version by allowing the user to run it with an argument to be used as the name for the greeting.
To access arguments passed to it when the command is executed, the program uses (*imports*) the `os` package from the Go standard library. [^1]
The `os` package *exports* a variable called `Args` [^2], a slice [^3] of string elements containing any arguments that are supplied when the command is executed.
The first argument in the array (0-based index) is always the full pathname to the program. Additional arguments, if any, will start at index 1.
```go
if len(os.Args) == 1 {
fmt.Println("Error: missing name")
os.Exit(1)
}
```
In this case, the program checks if the length of `Args` is exactly equal to one.
If true, then no additional arguments were provided, and the program will exit with an error after printing the error message.
Otherwise, there are at least two arguments and the name to greet will be accessed at the second element of the slice (index 1).
---
Next: [[6. Looping Over Args]]
[^1]: See: https://pkg.go.dev/os.
[^2]: See: https://pkg.go.dev/os#pkg-variables.
[^3]: A slice is an abstraction built on top of an array in Go. Arrays are rarely used directly. See: https://go.dev/blog/slices-intro.