Golang :command line argument with -> charecter

2020-05-02 12:28发布

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 it only accepts till '1-' . '>A' is being skipped.

Any help to resolve this issue is highly appreciated.

Thanks

1条回答
Fickle 薄情
2楼-- · 2020-05-02 12:40

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"
查看更多
登录 后发表回答