须藤猫<< EOF>文件不起作用,sudo su起作用 [英] sudo cat << EOF > File doesn't work, sudo su does
本文介绍了须藤猫<< EOF>文件不起作用,sudo su起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在bash的命令提示符下尝试了以下操作:
I tried the following on the command prompt in bash:
sudo cat << EOF > /etc/yum.repos.d/some-name.repo
#Content
#....
#...
EOF
它抱怨:
-bash: /etc/yum.repos.d/some-name.repo: Permission denied
然后我做了sudo su
并尝试了完全相同的操作,除了cat
之前的sudo
,并且它没有任何问题.我在上面缺少什么?
Then I did sudo su
and tried the exact same thing except the sudo
before cat
, and it worked without any problem. What am I missing in the above ?
推荐答案
在使用您的UID运行时,输出重定向(例如>)是由bash而不是cat执行的.要使用root的UID运行,请使用sudo:
Output redirection (e.g., >) is performed by bash, not by cat, while running with your UID. To run with root's UID use sudo:
sudo bash -c 'cat << EOF > /etc/yum.repos.d/some-name.repo
line1
line2
line3
EOF'
这篇关于须藤猫<< EOF>文件不起作用,sudo su起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文