Reputation: 15562
I want to append some text to a privileged file /root/.profile
. I used following scripts to do so.
sudo echo "blabla" >> /root/.profile
it still complains with permission denied. What is the right way to do so? I am using bash4
on ubuntu12.04
Upvotes: 1
Views: 496
Reputation: 31728
Yes the shell will open /root/.profile before running sudo. You need something like:
echo 'blabla' | sudo tee -a /root/.profile
Upvotes: 4
Reputation: 14714
The stream redirect >>
is evalutated before sudo
is even called. The simple answer is to put the whole thing inside a sub-shell:
sudo sh -c "echo 'blabla' >> /root/.profile"
Upvotes: 5