One common technique that is somewhat fragile is:
#!/bin/sh
test -z "$NOEXEC" && { NOEXEC=1 exec "$0" "$@" 2>&1 | tee logfile; exit; }
...
This will discard the return value and exit with the value returned by tee
. This may or may not be an issue, and may be the desired behavior.