I want to print the build time when program starts, like:
package main
import "fmt"
var BuildTime string
func main() {
fmt.Println(BuildTime)
}
I tried set an environment variable to current time by set bt (date)
, make sure echo $bt
shows the time.
Then build with go build -ldflags "-X main.BuildTime=$bt"
, but it fails to build and shows the usage of some linker, like:
I tried some system variable like $USER/$PWD/$TERM, like go build -ldflags "-X main.BuildTime=$USER"
, all work fine, why not work for $bt
?
I'm using fish shell, but I also tried bash, same problem.