Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 " $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: foo.l

share|improve this question

marked as duplicate by Michael Mrozek Jul 18 '11 at 16:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

So what's the question? How to change permissions? – Philomath Jul 18 '11 at 16:06
My apologies i added a question mark where the colon was. – chrisjlee Jul 18 '11 at 16:15
up vote 1 down vote accepted

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

However, you could try

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

and see if that works as needed.

share|improve this answer
Awesome that worked. Thanks! What a strange command: tee ! – chrisjlee Jul 18 '11 at 16:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.