I have to do an assignment like m=7 from the C++ command line application. When I run this application using sudo MyApp, the command present in the program fails to execute.
sudo m=7
fails with the following error
Command Not Found.
Is there any way so that I can assign value to a variable with the sudo keyword present in the command?
Basically I want a way to do sudo {Assignment} i.e. sudo m=3. Thanks.
The
sudocommand allows one to run an external command as a given user (default: root).m=7is not an external command and hence cannot be run by sudo. It is a variable assignment statement that is directly interpreted and executed by the current shell.The
Command not foundmessage indicates that sudo failed to find an executable command named m=7.In fact, it is hard to imagine what the intended goal of running
sudo m=7might be. If you want to assign 7 to the shell variablemyou do not need any special privileges orsudofor that, just runm=7. If you want to open root shell and execute some commands there starting withm=7just start withsudo bashand then issue them=7statement.