I note that the correct answer has already been given, but I am attempting to summarize into a more succinct answer.
1. There is nothing to prevent you from having literal tab characters in a here document.
To type a literal tab at the Bash prompt, you need to escape it. The escape character is ctrl-V (unless you have custom bindings to override this).
$ echo -n 't<ctrl-v><tab>ab' | hexdump -C
00000000 74 09 61 62 |t.ab|
00000004
In most any programmer's editor, it should be trivial to insert a literal tab character (although some editors might want escaping, too. In Emacs, ctrl-Q TAB inserts a literal tab).
For legibility, it might be better to use some sort of escape instead of a literal tab character. In Bash, the $'...' string syntax is convenient for this.
2. To prevent variable expansion, quote all dollar signs, or put the here doc terminator in quotes.
$ hexdump -C <<HERE
> t<ctrl-v><tab>\$ab
HERE
00000000 74 09 24 61 62 0a |t.$ab.|
00000006
$ hexdump -C <<'HERE'
> t<ctrl-v><tab>$ab
HERE
00000000 74 09 24 61 62 0a |t.$ab.|
00000006
In this context, it doesn't matter whether you use single or double quotes.
3. I am not sure I understand this subquestion. The purpose of a here document is to embed it in a script. The previous example illustrates how to pass a here document to hexdump in a script, or at the command line.
If you want to use the same here document multiple times, there is no straightforward way to do that directly. The script could write a here document to a temporary file, then pass that temporary file to multiple commands, then erase the temporary file. (Take care to use trap
to remove the temporary file also in case the script is interrupted.)
You could also put the contents of the here document in a variable, and interpolate that.
# Note embedded newlines inside the single quotes,
# and the use of $'...\t...' to encode tabs
data=$'coffee\t$1.50
tea\t$1.50
burger\t$5.00'
# Run Word Count on the data using a here document
wc <<HERE
$data
HERE
# Count number of tab characters using another here document with the same data
grep -c $'\t' <<HERE
$data
HERE
You could equivalently use echo -E "$data" | wc; echo -E "$data" | grep -c $'\t'
but using echo is not very elegant and might be less portable (though if your target is bash, all echos should be the same. If your target is Bourne shell in general, you might also spend an external process for each echo).