Bash write output in terminal and file

Asked

Viewed 168 times

1

I am creating a script and need the outputs to be shown in the terminal, but also saved in a file

#!/bin/bash
echo "Olá Mundo"

and I am redirecting the output to the file as follows

./teste.sh > saida.txt

so the string Ola mundo is correctly saved in the file.

How do I make that in addition to the file it is also printed on the screen at the same time?

1 answer

4


From what I understand your question, you could do it through command tee that does what is in the image below, obtained from this website:

inserir a descrição da imagem aqui

Passes command and it saves in the file and plays on stdout, so the code would be:

echo "Olá Mundo" | tee saida.txt
  • 1

    Congratulations on the answer.

  • 1

    @Vivisantana thanks,

  • 2

    It worked here. I was trying something with ./test.sh > saida.txt 2>&0 2>&1 unsuccessful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.