Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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

1 Answer 1

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 "127.0.1.1    $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.