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 sequences "\\" 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.
The
sh.Exec
family of functions used to useos.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 compatibleExpand
function to allow escaping the environment-variable syntax, plus an accompanyingEscape
function to producing escaped strings.This technically breaks backward compatibility; any existing code that has used the sequences "\\" or "\\$" in its command arguments will need to be updated. Although the compatibility argument prevents
os.Expand
from changing, documentation forsh.Exec
hasn't actually stated that it follows all the same rules asos.Expand
, so it's possible to view this change as merely a bugfix, formalizing a new syntax that had not previously been established.Fixes #434