I'm trying to run various commands through sudo, where the equal sign (=) is a part of the command. Under certain cases, it seems that sudo confuses that sign for setting and environment variable.
I see this in sudo(8) man:
Environment variables to be set for the command may also be passed on the command line in the form of VAR=value...
This is a problem for me, for example, if I try to run a command like:
sudo -i "cd /tmp; /usr/bin/hadoop fs -D dfs.replication=2 -ls"
It actually goes into a root shell instead of executing the command, since the command is misinterpreted. I see this in sudo.log:
Apr 29 16:11:40 : my_user : TTY=pts/7 ; PWD=/home/my_user ; USER=root ; ENV=cd /tmp; /usr/bin/hadoop fs -D dfs.replication=2 -ls ; COMMAND=/bin/bash
As you can see, the command is actually misinterpreted as trying to set ENV.
If I remove the preceeding
cd /tmp; it will work. However, for some of my stuff, I have to run a cd command or something similar first.
This seems to be because of the equal sign which causes sudo to think I'm setting ENV. If I remove the equal sign (i.e. remove
-D dfs.replication=2 ), then it works, and logged correctly:
Apr 29 16:08:46 : my_user : TTY=pts/7 ; PWD=/home/my_user ; USER=root ; COMMAND=/bin/tcsh -c cd /tmp; /usr/bin/hadoop fs -ls
So my question is: How do I escape this = character, and/or get sudo read the command as a whole command, instead of thinking an equal sign is setting an environment variable?