0

Possible Duplicate:
Redirecting stdout to a file you don't have write permission on

I'm new i'm trying to learn shell scripting.

Is there a way to force a concatenation and override the privileges doing the following one line command?

read domain; echo "127.0.1.1 $domain " >> /etc/hosts

What i'm trying to do is just create a simple script to type in the domain and then add it to my hosts file for development. Since my hosts file has restrictive permissions (even though i'm the only user with sudo powers) it won't let go.

The ideal output would just do the following:

127.0.0.1 foo.l

chrisjlee
  • 8,523

1 Answers1

1

Can't. >> is interpreted by the shell, so the sudo command effectively ends before that.

However, you could try

read domain; echo "127.0.1.1    $domain  " | sudo tee --append /etc/hosts 

and see if that works as needed.