The problem is in how your shell interprets arguments. If I am in bash (most other shells work the same way), and I type the command
sudo /bin/bash -c "echo foo && echo bar"
sudo
is invoked with everything after it as arguments. However, the shell processes each argument before passing it in to sudo
. One of the things it does is remove quotes around quoted arguments. Therefore, the arguments that sudo
gets as its argv
value are an array that looks like this (one argument per line):
/bin/bash
-c
echo foo && echo bar
sudo
combines these with spaces and compares that to the commands in the sudoers file (it is actually a bit more complicated than this since it does wildcard replacement, etc.). Thus, the command it actually sees you executing, for the purposes of checking permissions is
/bin/bash -c echo foo && echo bar
When I put that command in my sudoers file, I am not prompted for a password when I enter
sudo /bin/bash -c "echo foo && echo bar"
However I am also not prompted for a password when I enter any of these commands or other like them.
sudo /bin/bash "-c echo foo && echo bar"
sudo /bin/bash "-c echo" foo "&& echo" bar
sudo /bin/bash -c echo "foo && echo" bar
In general, as far as I know, there is no way for sudo
(or any program) to know exactly what command got entered, only what it gets converted to by the shell for execution purposes.
sudo /bin/bash -c \"echo foo && echo bar\"
- without success. – Posh\&\&
? – Incontrollable%wheel myhostname =NOPASSWD: /bin/bash -c "echo foo && echo bar"
works well with Ubuntu 11.04.sudo /bin/bash -c echo foo
without quotation marks won't work. – Ishii