February 22, 2010
Here Documents Magic

Check this two examples of here document in BASH.

First one, classic:

$ cat >file-sh<<EOF
string="hello world"
echo $string
EOF

Second one, new magic I learnt today:

$ cat >file2-sh<<"EOF"
string="hello world"
echo $string
EOF

There’s a big difference:

$ diff file-sh file2-sh 
2c2
< echo 
---
> echo $string

First notice, and it saved my day!

Update: if you’re reading this post through your feed reader, the examples may look weird. Blame Tumblr: the way they generate the RSS it’s broken.

by jjm on 4:13pm  |   URL: http://tumblr.com/ZPorZyO9IGo
(View comments
Blog comments powered by Disqus