July 29, 2008

write multiple lines into a file in script

cat (refereed to as HERE document), see more at http://en.wikipedia.org/wiki/Heredoc:

cat >tempfile.txt < abc
> def
> acb
> DELIM
tzhang@colinux:~/temp$ cat abc
abc
def
acb
tzhang@colinux:~/temp$


By default variables and also commands in backticks are evaluated:

 $ cat <<> Working dir $PWD
> EOF
Working dir /home/user

This can be disabled by setting the label in the command line in single or double quotes:

 $ cat << "EOF"
> Working dir $PWD
> EOF

Working dir $PWD

Appending a minus sign to the <<>

---------------------------------
echo with quote:

echo "abc
def
acb" >tempfile.txt

----------------------------

No comments:

Post a Comment