tty >/dev/null || { urxvt -e /bin/sh -c "tty >/tmp/proc$$; while test x; do sleep 1; done" & while test ! -f /tmp/proc$$; do sleep .1; done; FN=$(cat /tmp/proc$$); rm /tmp/proc$$; exec >$FN 2>$FN <$FN; }
tty
.tty
and saves it to a filename. $$
was set by the original script and is its PID. That is opened in the background using &
and then the original script waits for the filename to appear, then reads and removes it.exec
that contains nothing but redirections (of stdout, stderr, and stdin) so they will apply to every command in the rest of the script file.tty >/dev/null || { urxvt -hold -e "$0" "$@" & exit; }