is it a good idea to use "sudo bash -c" instead of "sudo" forever? [closed]

1st of all, we are talking about Debian/Ubuntu OS only.

2nd of all, we are talking about a non-root user with sudo privilege only.



So question is,

Is there any occasion that can not use sudo bash -c 'command' but only sudo command ?

is it a good idea to use sudo bash -c instead of sudo forever?


Solution 1:

If you are not using bash, then bash -c runs the command with bash, and sudo command runs the command with your shell.

If you are using bash, then bash -c creates another bash for you to run your script in, which may actually cause problems regarding variables.

Try this example

S=2
echo $S
bash -c echo $S

You will get different output!