Dash equivalent of self-redirection of script output

You can just do:

{ commands
....
} | logger -t my_awesome_script

You can do that with any shell.

If you don't like the way it looks, maybe make the script wrap itself in a function.

#!/bin/sh
run() if     [ "$run" != "$$" ] || return
      then   sh -c 'run=$$ exec "$0" "$@"' "$0" "$@" |
             logger -t my-awesome-script
      fi
#script-body
run "$@" || do stuff

Process substitution is easily simulated with named pipes.

mkfifo logger_input
logger -t my_awesome_script < logger_input &
exec > logger_input
echo 1
echo 2
echo 3

In fact, named pipes are one of the mechanisms (the other being /dev/fd) with which process substitution can be implemented in bash.


I don't think this is possible in dash. As far as I can tell from its man page, it has no support for process substitution.

As a workaround, you could try what mikserv suggested, or you can redirect everything to a file, and then after your script is finished (presumably this is in a script), add that file's contents to logger:

$ exec > ~/foo/foo.txt
$ ls
$ echo something
$ cat foo/foo.txt | sudo logger -t my-awesome-script