mage
mage copied to clipboard
sh.RunV removing dollar sign character from strings
given: sh.RunV(command, action, "--user", "foo", "--password", "bar$baz")
The password will always be converted to: barbaz.
I've tried to escape: \$, $$, 'bar$baz' I've tried byte buffers and string slices.
RunV always eats the dollar sign even when it's not meant to be a variable replacement.
This is absolutely a problem. There's some designs about how to turn this on or off. I'm sorry for the problems it's causing you. I'll try to come up with a good fix for this.
I hit this problem today, and here's the hack I came up with to get around it after studying the os package's implementation.
The os package treats $
followed by any special character ('*', '#', '$', '@', '!', '?', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
) as the mapping of that special character. So $$
will be replaced by the mapping of $
which can be itself.
Replace:
err := sh.RunV(cmd, args...)
With:
env := map[string]string{"$": "$"} // Escape hack: "$$FOO" becomes "$FOO"
_, err := sh.Exec(env, os.Stdout, os.Stderr, cmd, args...)
If you wanted to support this style of escaping ($$
=> $
), it would be a simple change to the mapping function in Exec... and maybe you'd want to do the same thing in the target package.