Golang:命令行参数使用 -> 字符。

huangapple go评论89阅读模式
英文:

Golang :command line argument with -> charecter

问题

我需要接受命令行参数来运行一个Go程序,格式如下:

 go run app.go 1->A

我正在使用os.Args[1]。但它只接受到'1-',而'->A'被跳过了。

非常感谢您提供解决此问题的任何帮助。

谢谢。

英文:

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

得分: 2

你的shell将>解释为IO重定向。shell将文件A打开作为命令的标准输出,并将参数1-传递给该命令。

为了避免这种情况,请引用该参数:

go run app.go "1->A"
英文:

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"

huangapple
  • 本文由 发表于 2016年4月23日 11:19:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/36806262.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定