How do you type a tab in a bash here-document?

D W picture D W · Sep 17, 2010 · Viewed 18.6k times · Source

The definition of a here-document is here: http://en.wikipedia.org/wiki/Here_document

How can you type a tab in a here-document? Such as this:

cat > prices.txt << EOF
coffee\t$1.50
tea\t$1.50
burger\t$5.00
EOF

UPDATE:

Issues dealt with in this question:

  1. Expanding the tab character
  2. While not expanding the dollar sign
  3. Embedding a here-doc in a file such as a script

Answer

chuck picture chuck · Sep 17, 2010
TAB="$(printf '\t')"

cat > prices.txt << EOF
coffee${TAB}\$1.50
tea${TAB}\$1.50
burger${TAB}\$5.00
EOF