Why sudo cat gives a Permission denied but sudo vim works fine?

前端 未结 6 1943
生来不讨喜
生来不讨喜 2021-01-29 22:41

I am trying to automate the addition of a repository source in my arch\'s pacman.conf file but using the echo command in my shell script. However, it fails like th

6条回答
  •  伪装坚强ぢ
    2021-01-29 23:03

    The problem is that the redirection is being processed by your original shell, not by sudo. Shells are not capable of reading minds and do not know that that particular >> is meant for the sudo and not for it.

    You need to:

    1. quote the redirection ( so it is passed on to sudo)
    2. and use sudo -s (so that sudo uses a shell to process the quoted redirection.)

提交回复
热议问题