Golang :command line argument with -> charecter

后端 未结 1 1917
半阙折子戏
半阙折子戏 2021-01-26 07:04

I need to accept command line argument to run a Go program in the below format:

 go run app.go 1->A

I am using os.Args[1]. But

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 07:15

    Your shell is interpreting the > as IO redirection. The shell opened the file A as standard output for the command and passed the argument 1- to the command.

    Quote the argument to avoid this:

    go run app.go "1->A"
    

    0 讨论(0)
提交回复
热议问题