How do I get Go to evaluate the $PATH variable. I currently just prints "$PATH"
I have the following code
package main
import (
"fmt"
"log"
"os/exec"
)
func main() {
out, err := exec.Command("echo","$PATH").Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s
",out)
}
You need to use os.Getenv("PATH")
package main
import (
"fmt"
"log"
"os/exec"
"os"
)
func main() {
out, err := exec.Command("echo",os.Getenv("PATH")).Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s
",out)
}