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

前端 未结 9 1304
深忆病人
深忆病人 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 13:17

    A little extension to the above answers. The trailing > directs the input into the file, overwriting existing content. However, one particularly convenient use is the double arrow >> that appends, adding your new content to the end of the file, as in:

    cat <> /etc/fstab
    data_server:/var/sharedServer/authority/cert /var/sharedFolder/sometin/authority/cert nfs
    data_server:/var/sharedServer/cert   /var/sharedFolder/sometin/vsdc/cert nfs
    EOF
    

    This extends your fstab without you having to worry about accidentally modifying any of its contents.

提交回复
热议问题