Thursday, June 12, 2025
HomeGolangOs.args and quoted string on commandline - Code Evaluate

Os.args and quoted string on commandline – Code Evaluate


ENVIRONMENT:
OS: Linux Fedora 38
GO VERSION: 1.20.6

CODE FRAGMENT:
for e := 0; e < len(os.Args); e++ {
println(fmt.Sprintf(“Args[%v]=%v”, e, os.Args[e]))
}

CLI LINE:
go run myprogram “xxx yyy”

RESULTS:
Args[0]=/tmp/go-build176778176/b001/exe/myprogram
Args[1]=xxx
Args[2]=yyy

QUESTION:
CharGPT tells me to make use of double quotes to surround the handed phrase.
https://chat.openai.com/share/7f7e4690-234f-4e4d-847f-88b90b13667a

The outcomes must be Args[1] holds the complete quoted phrase
and there must be no Args[2]. I would like the complete phrase.
What am I doing improper?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments