I am trying to output all
stdout
stderr
./script | tee somefile
#!/bin/sh
exec 2>&1 | tee somefile
echo "..."
The classical solution is to add something like this at the top of the script:
test -z "$REXECED" && { REXECED=1 exec $0 "$@" 2>&1 | tee -a somefile; exit; }
You might also like:
test -t 1 && { exec $0 "$@" 2>&1 | tee -a somefile; exit; }