How does “cat << EOF” work in bash?

前端 未结 9 1302
深忆病人
深忆病人 2020-11-22 12:24

I needed to write a script to enter multi-line input to a program (psql).

After a bit of googling, I found the following syntax works:

c         


        
9条回答
  •  余生分开走
    2020-11-22 12:54

    Using tee instead of cat

    Not exactly as an answer to the original question, but I wanted to share this anyway: I had the need to create a config file in a directory that required root rights.

    The following does not work for that case:

    $ sudo cat </etc/somedir/foo.conf
    # my config file
    foo=bar
    EOF
    

    because the redirection is handled outside of the sudo context.

    I ended up using this instead:

    $ sudo tee </dev/null
    # my config file
    foo=bar
    EOF
    

提交回复
热议问题