0

This is a really basic question, but I couldn't find it asked this basically in an existing question, so please flag this if it's been answered before.

I want to pipe stderr from a bash command to a file, but not prevent it from being displayed on the terminal during execution.

More specifically, I have this .sh file:

nslookup MadeUpName
nslookup MadeUpName2
nslookup MadeUpName3

and I'm doing this:

. ./myScript.sh 2>errors.txt

This works to pipe error messages to errors.txt, but now I can't see the errors in the terminal as they happen.

Michael Hoffmann
  • 2,361
  • 2
  • 22
  • 41

1 Answers1

0

You can use tee for displaying error and writing to an error file:

myScript.sh 2> >(tee error.log; exit)

If you want further information about this technique, see this page.

pscheid
  • 400
  • 4
  • 9
anubhava
  • 713,503
  • 59
  • 514
  • 593