How to take strings as command line arguments?

Hello, actually i want to make a Go program and combile it to run it on linux.
and it will take 2 string argument in command line and then check that if argument equals to this then do this.
like in command line

mygofile check os

in this, mygofile is a go file which is compiled to work on linux and check and os are arguments.
at the first, my program will read all the arguments then check if argument is equals to check then next it will check if argument is equals to os then it will print Yeah it’s OS and if not equals then print OOh Invalid.

actuallly i am unable to share here because i got this project from company and that code contains some URL and i am not allowed to share that URLs publically

Take a look at this blog Post about using args.

If that can not answer your question, you need to provide some better examples. You can strip Off all the secret company stuff or replace it with stub values if it’s indeed needed for your example to run.

already checked that buddy !

that receives argument in char or slice.

i want to read argument in string and send that argument as a string to a function.

i want to read 2 arguments from command line and send that 2 arguments to a function.
those arguments are - check os

package main

import (

func checkOS(args []string) {
	if len(args) == 2 {
		if args[0] == "check" && args[1] == "os" {
			fmt.Println("Yeah it’s "+ runtime.GOOS)
	fmt.Println("OOh Invalid")

func main() {


$ go run checkos.go check os
Yeah it’s linux
$ go run checkos.go check arch
OOh Invalid

buddy, thanks a lot

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.