-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exec args always expanded #434
Comments
Similar problem here. I am calling sh.Exec with a list of arguments one of which contains $. I want the literal $ but mage tries to expand it and I found no way to prevent this. |
The `sh.Exec` family of functions used to use `os.Expand` to expand environment variables in command arguments, but that function offers no escape syntax -- no way to avoid expanding dollar signs that the caller really wants to include on the command line. This commit implements a new, mostly compatible `Expand` function to allow escaping the environment-variable syntax, plus an accompanying `Escape` function to producing escaped strings. This technically breaks backward compatibility; any existing code that has used the sequence "\\" or "\$" in its command arguments will need to be updated. Although the compatibility argument prevents `os.Expand` from changing, documentation for `sh.Exec` hasn't actually stated that it follows all the same rules as `os.Expand`, so it's possible to view this change as merely a bugfix, formalizing a new syntax that had not previously been established. Fixes magefile#434
I've just submitted a PR that I think would solve this. But @hborham, note that for your example to work the way you want, you'd need to remove the apostrophes from your arguments. Apostrophes are one way to avoid having the shell expand environment variables. In doing so, the shell would strip the apostrophes from the argument prior to invoking the given command, so sh.Run("pact-broker", "create-webhook", sh.Escape("--user=admin:${user.bitbucketAppPassword}")) |
Within the
sh
package, args are being expanded in the case where normal sh command would not expand args within single quotes. Example command:pact-broker create-webhook --user='admin:${user.bitbucketAppPassword}'
${user.bitbucketAppPassword}
pact-broker create-webhook --user='admin:'
mage/sh/cmd.go
Lines 92 to 115 in 26cdb5c
The text was updated successfully, but these errors were encountered: