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

前端 未结 6 1996
生来不讨喜
生来不讨喜 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条回答
  •  Happy的楠姐
    2021-01-29 23:06

    STEP 1 create a function in a bash file (write_pacman.sh)

    #!/bin/bash
    
    function write_pacman {
     tee -a /etc/pacman.conf > /dev/null << 'EOF'
      [archlinuxfr]
      Server = http://repo.archlinux.fr/\$arch
    EOF
    }
    

    'EOF' will not interpret $arch variable.

    STE2 source bash file

    $ source write_pacman.sh
    

    STEP 3 execute function

    $ write_pacman
    

提交回复
热议问题