Command Line Arguments in Golang Last Updated : 17 May, 2020 Comments Improve Suggest changes Like Article Like Report Command-line arguments are a way to provide the parameters or arguments to the main function of a program. Similarly, In Go, we use this technique to pass the arguments at the run time of a program. In Golang, we have a package called as os package that contains an array called as "Args". Args is an array of string that contains all the command line arguments passed. The first argument will be always the program name as shown below. Example 1: Try to use offline compiler for better results. Save the below file as cmdargs1.go C // Golang program to show how // to use command-line arguments package main import ( "fmt" "os" ) func main() { // The first argument // is always program name myProgramName := os.Args[0] // it will display // the program name fmt.Println(myProgramName) } Output: Here, you can see it is showing the program name with full path. Basically you can call this as Os Filepath output. If you will run the program with some dummy arguments then that will also print as a program name. Example 2: Save the below file as cmdargs2.go C // Golang program to show how // to use command-line arguments package main import ( "fmt" "os" ) func main() { // The first argument // is always program name myProgramName := os.Args[0] // this will take 4 // command line arguments cmdArgs := os.Args[4] // getting the arguments // with normal indexing gettingArgs := os.Args[2] toGetAllArgs := os.Args[1:] // it will display // the program name fmt.Println(myProgramName) fmt.Println(cmdArgs) fmt.Println(gettingArgs) fmt.Println(toGetAllArgs) } Output: Comment More infoAdvertise with us Next Article Command Line Arguments in Golang P pganesh Follow Improve Article Tags : Go Language Write From Home Similar Reads Command Line Arguments in C++ Command-line arguments are arguments that are passed to a program when it is executed from the command line or terminal. They are provided in the command-line shell of operating systems with the program execution command.The main function of C++ generally has the following signature:C++int main(){ / 3 min read Function Arguments in Golang In Golang, functions are groups of statements used to perform tasks, with optional returns. Go supports two main ways to pass arguments: Pass by Value and Pass by Reference. By default, Go uses pass-by-value.Basic Terms in Parameter Passing to Functions:Actual Parameters: The arguments passed to a f 2 min read Command Line Argument in Scala The arguments which are passed by the user or programmer to the main() method are termed as Command-Line Arguments. main() method is the entry point of execution of a program. main() method accepts an array of strings. runtime. But it never accepts parameters from any other method in the program. Sy 2 min read How to Parse Command Line Arguments in Node ? Command-line arguments, in the context of a command-line interface (CLI), are text strings that provide extra information to a program when it is executed.In Nodejs, these arguments are accessible through an array known as argv (arguments values), where the shell passes all received command-line arg 3 min read Command Line Arguments in Objective-C In Objective-C, command-line arguments are strings of text that are passed to a command-line program when it is launched. They can be used to specify options or parameters that control the behavior of the program or to provide input data that the program can process. To access command-line arguments 2 min read Like