Sudo loses power in .travis.yml file

I try to config a environment from my .travis.yml file by adding line to /etc/hosts with sudo.
like sudo echo "one line >>/etc/hosts`.

But it raised error with “permission denied”. But I can create new dir with sudo. Did I miss anything?
Please help. Thanks.

Have you tried this on your machine? This should not work.

The I/O redirection with > only has user privilege, so you will have to use a command that does write to a file you need.

For example,

echo "one line" | sudo tee -a /etc/hosts

I chmod firstly and then with sudo it worked. you mean that the redirection only got the previlidge of real user not effective user? It is also a command, so I have to give it super user privilege too, right? I think that makes sense. Thanks.