Rakim Faoui
Rakim Faoui

Reputation: 107

What usage for << redirection in TCSH shell

I understand the < input redirection and the two > / >> output redirections (the double append content in file). But I don't understand << double input redirection.

For example echo "cat < input | wc > output" | tcsh produce this output file : 2 2 11 but with echo "cat << input | wc > output" | tcsh this produce this output file : 0 0 0.

What does << do? It seem that it don't send data to wc stdin but why?

Upvotes: 2

Views: 1509

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295373

In csh, as in POSIX-family shells, << starts a heredoc -- that is, a multi-line string terminated by a line containing only the word immediately after it. Thus, in the following example:

cat << input | wc > output
this is test data here
input

this is test data here is fed as stdin to cat, the stdout of which is fed as stdin to wc. (By the way, there's no point at all to using cat here; you could just wc <<input >output with the same effect, and with considerably less inefficiency).

Upvotes: 3

Related Questions