Go Command Line Arguments

When we need to execute a program with some arguments, we generally use command line argument. The arguments passed from the console can be received by the Go program and it can be used as an input.

The os.Args is used to get the arguments. The index 0 of os.Args contains the path of the program.

The os.Args[1:] holds provided arguments.

Go Command Line Argument Example 1

Command to run the program:


Go Command Line Argument Example 2


[/private/var/folders/by/w452m9913bj8_rmgzgjsvw9w0000gn/T/___cmd_go Tom Dick Harry]
[Tom Dick Harry]

Next TopicGo String

Hot Tutorials

Contact US


Go Command Args