Mahes Mahes - 1 year ago 107
Bash Question

Creating files with some content with shell script

I need to configure a server with few file and i want to do it programatically.

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

above files 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 somehting like this

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

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


Answer Source

You can use a here document:

cat <<EOF >/home/a.config
first line
second line
third line

You can place several of these in the same script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download