当前位置: 动力学知识库 > 问答 > 编程问答 >

csh - linux print to STDOUT and redirect to a file using single command

问题描述:

Is there a way to both echo the output of a command to the terminal and redirect to a file using a single file rather than using 2 separate commands in csh (for historical reasons i must use csh for this purpose). Currently I do this

echo "Hello World!"

echo "Hello World!" > textfile

echo "next line blah blah"

echo "next line blah blah" >> textfile

网友答案:

This is exactly what tee is for:

echo "Hello World!" | tee textfile

For multiple outputs, you can use

(
  echo "Hello World!"
  echo "next line blah blah"
) | tee textfile

or use the append option with tee.

echo "Hello World!" | tee textfile
echo "next line blah blah" | tee -a textfile
分享给朋友:
您可能感兴趣的文章:
随机阅读: