Search code examples
shellunixscripting

Creating files with some content with shell script


I need to configure a server with a few files and I want to do it programmatically.

I need to create files say /home/a.config, /var/spool/b.config, /etc/c.config

Files above have some contents (multi lines).

I want to create ONE shell script which can create all three file with multiple lines (around 10). I would like to know the how can I use CAT command to do that. (inside shell script).

I am looking something like this

echo " going to create  /home/a.config"

cat "HOW CAN I HAVE MULTIPLE LINES HERE?? " >  /home/a.config 

thanks


Solution

  • You can use a here document:

    cat <<EOF >filename
    first line
    second line
    third line
    EOF
    

    You can place several of these in the same script.