Command-Line Arguments
package main
import (
"fmt"
"os"
)
func main() {
// os.Args provides a slice of command-line arguments, including the program name.
argsWithProg := os.Args
// os.Args[1:] gives a slice of command-line arguments excluding the program name.
argsWithoutProg := os.Args[1:]
// Accessing a specific command-line argument by index.
arg := os.Args[3]
// Print the command-line arguments.
fmt.Println("Args with program name:", argsWithProg)
fmt.Println("Args without program name:", argsWithoutProg)
fmt.Println("Third argument (index 3):", arg)
}Last updated