4 Answers
4

The reason sudo echo "some words" >> /etc/apt/source.list doesn't work is because sudo is raising the privileges of the 'echo' command, and not the redirection.

The >> redirection causes the current shell to create/append to the file. It fails because your shell doesn't have permissions to do so.

The reason my answer works is that you are running the whole thing (echo and the redirection) in a new shell that has been sudo'd. sh -c ... invokes a new shell and runs the command given in that subshell. The sudo before it makes that subshell run withe escalated privileges.

The second sudo example doesn't make sense, because sudo takes a command to run, and that's not what you are passing. I bet you do have a file in the local directory called sudo now with contents "some words". Feel free to delete that :-)