You can set environment variables in an exec.Cmd:
https://golang.org/pkg/os/exec/#Cmd

% cat example.sh
#!/usr/bin/env bash

echo "The password is $password."

% export password=old_password

% bash example.sh
The password is old_password.


% cat example.go
package main

import (
"fmt"
"os"
"os/exec"
)

func main() {
c := exec.Command("bash", "example.sh")
c.Env = []string{"password=monkey"}
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
fmt.Printf("Command failed: %s\n", err)
}
}

% go run example.go
The password is monkey.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to