Consider the following program which I'm running via MinGW
:
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println(os.Args[1])
}
When I run the command go run test.go /home
it prints C:/Program Files/Git/home
.
I suspected that the shell might be expanding the relative path. But running echo /home
prints only /home
.
What is changing the argument for my golang program?
This must be MinGW
or the shell that you are running that expands the parameter - to confirm it is not Go specific, try a simple shell script that prints $0
and $1
and run it with the /home
parameter.