Mathew Abraham Mathew
Mathew Abraham Mathew

Reputation: 11

Redirect output and error in to both logfile and console in #/bin/sh

I want shell script output and error to be redirected to both file and console I use #/bin/sh and the following works in BASH but not in base shell (#/bin/sh). Any ways to achieve this in #/bin/sh?

set -x

exec > >(tee "logfile") 2>&1

And exec &> logfile will output only to file and not to standard output

Upvotes: 1

Views: 705

Answers (1)

shellter
shellter

Reputation: 37288

 /path/2/cmd 2>&1 | tee logfile

Is as old school as you can get.

IHTH

Upvotes: 2

Related Questions