Open
Description
As cd
is a shell builtin, it can't be executed as a sudo
command. When I do that:
@task
def test(ctx):
""" test command """
with ctx.cd('my/path'):
ctx.run("pwd") # Show correct path
ctx.sudo("whoami") # fails with: sudo: cd: command not found
The last command fail.
After a quick look in the source, sudo command appears to be:
cmd_str = "sudo -S -p '{0}' {1}{2}".format(prompt, user_flags, command)
with the cd prefix the executed command is
$ sudo -S -p cd my/path && whoami
where cd
is unknow inside sudo
.
To fix the issue, new sudo
command could be:
cmd_str = "sudo -S -p '{0}' {1} sh -c \"{2}\"".format(prompt, user_flags, command)
but not sure of all the consequences of this behaviour.