Skip to content

Commit d5db888

Browse files
committed
Fixes early var expanding, adds support for env vars with spaces
1 parent 508b539 commit d5db888

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

ssh.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ func (c *SSHClient) buildComand(task *Task) string {
306306

307307
switch inter {
308308
case "bash", "sh", "zsh", "ksh", "tcsh":
309-
return fmt.Sprintf("/usr/bin/env %s %s -c \"set -x\n%s\"", c.env, i, strings.Replace(task.Run, `"`, `\"`, -1))
309+
return fmt.Sprintf("/usr/bin/env %s %s -c 'set -x\n%s'", c.env, i, strings.Replace(task.Run, `'`, `\'`, -1))
310310

311311
// TODO: add support for python already called via env
312312
case "python", "python3":
313-
return fmt.Sprintf("/usr/bin/env %s %s -c \"%s\"", c.env, i, strings.Replace(task.Run, `"`, `\"`, -1))
313+
return fmt.Sprintf("/usr/bin/env %s %s -c '%s'", c.env, i, strings.Replace(task.Run, `'`, `\'`, -1))
314314

315315
default:
316-
return fmt.Sprintf("/usr/bin/env %s bash -c \"set -x\n%s\"", c.env, strings.Replace(task.Run, `"`, `\"`, -1))
316+
return fmt.Sprintf("/usr/bin/env %s bash -c 'set -x\n%s'", c.env, strings.Replace(task.Run, `'`, `\'`, -1))
317317
}
318318
}

sup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (sup *Stackup) Run(network *Network, commands ...*Command) error {
3636
// `export FOO="bar"; export BAR="baz";`.
3737
env := ``
3838
for _, v := range append(sup.conf.Env, network.Env...) {
39-
env += v.String() + " "
39+
env += v.QuotedString() + " "
4040
}
4141

4242
// Create clients for every host (either SSH or Localhost).

supfile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func (e EnvVar) String() string {
6464
return e.Key + `=` + e.Value
6565
}
6666

67+
func (e EnvVar) QuotedString() string {
68+
return e.Key + `="` + e.Value + `"`
69+
}
70+
6771
// AsExport returns the environment variable as a bash export statement
6872
func (e EnvVar) AsExport() string {
6973
return `export ` + e.Key + `="` + e.Value + `";`

0 commit comments

Comments
 (0)