Search This Blog

Thursday, June 06, 2013

shell add multiple lines EOF

To create a file with multiple lines from a shell script you can use the following recipe
rajulocal@hogwarts:~/work/tcsh$ cat add_multiple_lines_to_file.sh
#! /bin/tcsh -fx

mkdir -p ~/x
cat << EOF > ~/x/junk1
k
am
ara
ju
EOF
Run this script using
rajulocal@hogwarts:~/work/tcsh$ ./add_multiple_lines_to_file.sh
mkdir -p /home/rajulocal/x
cat
The output will be stored in ~/x/junk1
rajulocal@hogwarts:~/work/tcsh$ cat ~/x/junk1
k
am
ara
ju
For further information
  1.  read the section on "Here-documents" in http://docstore.mik.ua/orelly/unix/ksh/ch07_01.htm
  2. http://en.wikipedia.org/wiki/Here_document
  3. search for "here document" in google

Followers