Skip to content

Commit 76271ef

Browse files
committed
Also save environment variables when saving a command
1 parent c392f6d commit 76271ef

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: v2/lastcmd.go

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func saveCommand(cmd *exec.Cmd) error {
5757
// Strip the leading /usr/bin/sh -c command, if present
5858
commandString := getCommand(cmd)
5959

60+
// Add environment variables
61+
for _, assignment := range cmd.Env {
62+
commandString = assignment + " " + commandString
63+
}
64+
6065
// Write the contents, ignore the number of written bytes
6166
_, err = f.WriteString(fmt.Sprintf("#!/bin/sh\n%s\n", commandString))
6267
return err

0 commit comments

Comments
 (0)