Javatpoint Logo
Javatpoint Logo

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:

Output:

Go Command Line Argument Example 2

Output:

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

Next TopicGo String




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA