0
$ cat<<EOF
> a
> EOF
a

Can I automatically redirect the stream vs typing into stdin? I have tried but this is what I get.

[debian:~]$ cat <<(printf "EOF\na\nEOF\n")
-bash: syntax error near unexpected token `('
[debian:~]$ cat <(printf "EOF\na\nEOF\n")
EOF
a
EOF

1 Answer 1

0

A here-doc is just one syntax for passing a particular input to the stdin of a program. But it's not the only one. You could also use:

  • a pipe:

    printf "a\n" | cat
    
  • a here-string:

    cat <<< "a"
    
  • process substitution (as you already did):

    cat < <(printf "a\n")
    

(Note that the here-string will add a newline to the end of the given string. The others won't so I added one manually with printf.)

Passing the EOF strings to cat isn't probably very useful, it's just part of the here-doc syntax.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .