capistrano/sshkit — pull request #143 by townsen (2014-05-15 19:42:44+00:00)
Title: Delay interpolation in as() block

When running commands within an as() block, the sudo command that is
generated uses double quotes. This has the unexpected effect of
evaluating any shell variables in the host.user environment and not that
of the as(user).

This change uses single quotes, so that any interpolation is delayed
until the command is run. This means that the following
two fragments return the same value for home:

on roles(:all) do
host.user = 'fred'
home = capture, :echo, %q[$HOME]
end

on roles(:all) do
# Where the default user has sudo access to fred
as 'fred' do
home = capture, :echo, %q[$HOME]
end
end

Prior to this change the second fragment would have required the $
symbol to be escaped like so: \$

Unfortunately this change may break existing code! But it does seem slightly more consistent!