Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 3017  / 2 Years ago, mon, june 27, 2022, 3:24:52

Is this normal?



> sudo -u misc -i "ls"
note test tmp
> sudo -u misc -i "ls ~"
-bash: ls ~: command not found
> sudo -u misc -i "ls ~"
-bash: ls ~: command not found
> sudo -u misc -i "foo=bar"
[misc]


Anything that's got a space in it seems to be interpreted as a single command, which is unrecognised. Even weirder, setting any environment variable drops me into the other user's account. How can I run those commands as expected?


More From » 10.04

 Answers
5

The command and arguments passed to sudo should not be surrounded in quotes, so you can try



sudo -u misc -i ls -l


but



sudo -u misc -i ls ~


should not list misc's home directory content, but your home, because the ~ character is expanded before been passed to sudo. You could try to avoid this using



sudo -u misc -i ls '~'


but this again doesn't work, because sudo do not invoke a shell to execute its command, so ~ has no meaning out of a shell.



Finally, the solution could be



sudo -u misc -i bash -c 'ls ~'

[#41143] Monday, June 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chilgirlguid

Total Points: 123
Total Questions: 114
Total Answers: 121

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
;