0

How to combine these two commands?

./script.sh > logfile.log 

and

./script.sh 2> logfile.log

Thank you!

3
  • 1
    How do you mean combine? You want both of their output to go to the log file? Commented Apr 26, 2016 at 8:23
  • Is it two different scripts? If so then use: ./s1.sh > log; ./s2.sh 2>> log see the append >> Commented Apr 26, 2016 at 8:48
  • It's one script and I do want both of their output to go to the log file Commented Apr 26, 2016 at 8:53

1 Answer 1

3

In bash, to redirect both standard output and standard error to the same file, you can write

./script.sh &> logfile.log

If you want to be compatible with other shells,

./script.sh > logfile.log 2>&1
Sign up to request clarification or add additional context in comments.

3 Comments

The first only works in bash 4+
When you are logging, you might need to append log file instead of overwriting it, so simple change to ./script.sh >> logfile.log 2>&1.
thank you! second option works perfect )

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.