mage icon indicating copy to clipboard operation
mage copied to clipboard

Exec args always expanded

Open hborham opened this issue 1 year ago • 2 comments

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}'

  1. Via normal shell the single quotes will not expand ${user.bitbucketAppPassword}
  2. Via mage the expansion occurs and the actual command becomes: pact-broker create-webhook --user='admin:'

https://github.com/magefile/mage/blob/26cdb5c7369a9b03981eb906dd3606c566e45c16/sh/cmd.go#L92-L115

hborham avatar Jul 07 '22 15:07 hborham

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.

fergonco avatar Aug 02 '23 11:08 fergonco

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 pact-broker would receive literally --user=admin:${user.bitbucketAppPassword} as its argument. Using my PR, you might write code like this:

sh.Run("pact-broker", "create-webhook", sh.Escape("--user=admin:${user.bitbucketAppPassword}"))

rkennedy avatar May 01 '24 21:05 rkennedy