Print bash script output to log file

I have bash script:

echo "Hello world"
ls -la 

How to ask this script print stdout and stderr to info.log file?

How to ask this script print stdout and stderr to info.log file and screen?

1 Answer

You could run the script like so to redirect both stdout and stderr to the file.

./yourScript.sh > info.log 2>&1

To redirect to a file as well as the console, you can use tee

./yourScript.sh 2>&1 | tee info.log
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like