如何使用bash在/ etc / profile中编写权限被拒绝

时间:2018-06-25 19:34:23

标签: bash ubuntu permissions environment

我正在创建一个bash脚本来设置Ubuntu 16.04 lts操作系统,以下载,安装和进行其他操作,而无需分别介绍每个命令,并且我必须写在/ etc / profile文件中以添加PATH环境变量。当我的代码进入该行时,它显示“权限被拒绝”消息,这就是我所拥有的:

sudo echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
bash: /etc/profile: Permission denied

你知道我该怎么解决吗?

2 个答案:

答案 0 :(得分:4)

Shell i / o重定向发生在之前,shell执行命令...换句话说,当您编写时:

sudo somecommand >> /etc/profile

>> /etc/profile部分是作为当前用户而不是root执行的。这就是为什么您会收到“权限被拒绝”消息的原因。有多种解决方法。您可以运行:

sudo sh -c "echo export PATH=$PATH:/usr/local/go/bin >> /etc/profile"

或者您可以利用-a命令的append(tee)标志:

echo "export PATH=$PATH:/usr/local/go/bin" | sudo tee -a /etc/profile

答案 1 :(得分:0)

    "C_Cpp.clang_format_fallbackStyle": " {BasedOnStyle: Google, AllowShortCaseLabelsOnASingleLine: true, AlignConsecutiveDeclarations: true, AllowShortFunctionsOnASingleLine: All, AlignTrailingComments: true, Language: Cpp, AlwaysBreakAfterReturnType: None, PenaltyReturnTypeOnItsOwnLine: 9999, PointerAlignment: Left, SortIncludes: true, IndentWidth: 4, ColumnLimit: 0, BreakBeforeBraces: Allman, SpacesBeforeTrailingComments: 5, AlignAfterOpenBracket: true, AlignConsecutiveAssignments: true, AlignConsecutiveMacros : true}",