-2

I'm trying to create a simple command line calculator which takes in 3 arguments operator int1 int2 where operator is can be either +,-,*,/ whenever I add * to the arguments it adds additional arguments. How would I go about reading * from arguments.

OS: Ubuntu x64
Build Command: go build main.go

Executed with + as a command line argument
Run Command: ./main + 2 2
Output: [./main + 2 2]

Executed with * as a command line argument
Run Command: ./main * 2 2
Output: [./main build main main.go main.go.bak 2 2]

Example Code

package main

import (
  "os"
  "fmt"
)

func main() {
  args := os.Args
  fmt.Println(args)
}
MFK34
  • 129
  • 2
  • 11

1 Answers1

1

On the command line, * is replaced with all files and directories in the current directory before the command is actually ran. In order to avoid this, instead do .\main "*" 2 2