How do you use output redirection in combination with here-documents and cat?
143
votes
3
answers
112052
views
Let's say I have a script that I want to pipe to another command or redirect to a file (piping to
sh
for the examples). Assume that I'm using bash.
I could do it using echo
:
echo "touch somefile
echo foo > somefile" | sh
I could also do almost the same thing using cat
:
cat somefile
EOF
But if I replace "EOF" with "EOF | sh" it just thinks that it's a part of the heredoc.
How can I make it so that cat
outputs text from stdin, and then pipes it to an arbitrary location?
Asked by strugee
(15371 rep)
Aug 28, 2013, 04:41 AM
Last activity: Dec 18, 2023, 03:02 AM
Last activity: Dec 18, 2023, 03:02 AM