简体   繁体   中英

pipe here document command to log file

Quite often I'll use the following construct to pipe output to a log file, keeping the output also on the display

./command 2>&1 | tee output.log

I'm trying to do something similar, but with using a here document:

./command << HEREDOC
params
HEREDOC 2>&1 | tee output.log

This doesn't work - is it possible to achieve this?

Sure.

./command <<HEREDOC 2>&1 | tee output.log
params
HEREDOC

The here-document doesn't begin until the next line. The rest of the command is parsed as normal.

An example with expr :

xargs expr << HEREDOC | tee output.log
10 + 11
HEREDOC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM