#!/usr/bin/env osh : : osh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: fd0to2.osh 534 2008-10-31 21:21:06Z jneitzel $ " : : " The author of this file, J.A. Neitzel , " : " hereby grants it to the public domain. " : : : " NOTE: The new fd2 `-e' command-line option in osh-20081026 obviates " : " the need for this command file. " : : : " Read data from file descriptor 0 and write it to file descriptor 2. " : " However, in the case where writing to file descriptor 2 would fail, " : " attempt to write the data to `/dev/tty' as the default case. Data " : " may come from a regular file, a FIFO, or a pipe. It may not come " : " from a terminal device; a diagnostic is printed in such a case. " : : " It is assumed that the format of the ``data'' is ``text'' which can " : " be safely written to a terminal device, but this is not enforced. " : : " If the length of the data is greater than zero bytes, exit with a " : " non-zero status; otherwise, exit with a zero status. " : : " usage: fd0to2 " : : : " Check for expected script name. " : : >>$0'' <'' killer $0'' fd0to2 : : " Perform all necessary actions for setup: " : : " 1) Create a temporary directory; " : " 2) Test if data would come from a tty, and exit if true; " : " 3) Read data (if any), and write it to a temporary file; " : " 4) Test size of data, and exit or continue as appropriate. " : if ! { mkdir -m 0700 /tmp/fd0to2-$$ } if { exit } false if -t 0 <- if $s != 0 goto Not_a_tty echo 'fd0to2: '$t': Invalid data source' >/dev/tty rmdir /tmp/fd0to2-$$ ; false ; exit : Not_a_tty cat <- >/tmp/fd0to2-$$/data if ! -s /tmp/fd0to2-$$/data if { rm -rf /tmp/fd0to2-$$ } exit : : " Write the data to the appropriate destination. " : if -w /dev/stderr goto STDERR if -w /dev/fd/2 goto FD2 : default cat /dev/tty ; goto Done : STDERR cat /dev/stderr ; goto Done : FD2 cat /dev/fd/2 : Done rm -rf /tmp/fd0to2-$$ ; false