将文本附加到"/root/.profile"

Ric*_*ard 1 bash sudo

我想将一些文本附加到特权文件/root/.profile.我使用以下脚本来执行此操作.

sudo echo"blabla">> /root/.profile

它仍然在申请被拒绝的情况下抱怨.这样做的正确方法是什么?我使用bash4ubuntu12.04

Okt*_*ist 5

甚至在调用>>之前,将重新定义流重定向sudo.简单的答案是将整个内容放在子shell中:

sudo sh -c "echo 'blabla' >> /root/.profile"
Run Code Online (Sandbox Code Playgroud)